Posts

Showing posts with the label C programming

SUM SERIES

Image
          SUM OF SERIES         1.SUM OF SERIES 1+1/2+1/3+1....1/N        #include <stdio.h> main () { int i , n ; float sum = 0 ; printf ( "Enter value of n\n" ); scanf ( "%d" ,& n ); for ( i = 1 ; i <= n ; i ++) { sum +=( float ) 1 / i ; } printf ( "The value of\n" ); for ( i = 1 ; i <= n ; i ++) { if ( i < n ) { printf ( "1/%d+ " , i ); } else { printf ( "1/%d= " , i ); } } printf ( "%f\n" , sum ); } •Output Enter value of n 8 The value of 1/1+ 1/2+ 1/3+ 1/4+ 1/5+ 1/6+ 1/7+ 1/8= 2.717857 2.SUM OF SERIES 1/1!+1/2!+1/3!+1....+N /N! main() { int i,n; float sum=0; printf("Enter value of n\n"); scanf("%d",&n); for(i=1;i&lt;=n;i++) {  sum+=(float)i/factorial(i); } printf("The value of\n"); for(i=1;i&lt;=n;i++) {  if(i&lt;n)  {   printf("%d/%d!+ ",i,i);  }  else  {   printf("%d/%d!= ",i,i);  } } pri...

GRAPHICS

Image
                       1.CIRCLE  #include<stdio.h> #include<graphics.h> #include<conio.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode circle(150,200,50); getch(); closegraph();//closing of graphic mode return 0; } •Output 2.LINE #include<stdio.h> #include<graphics.h> #include<conio.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode line(150,150,250,250); getch(); closegraph();//closing of graphic mode return 0; } •Output 3.RECTANGLE #include<stdio.h> #include<graphics.h> #include<conio.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode rectangle(150,150,350,250); ...

FILE HANDLING

10.1.1 File Pointers It is not enough to just display the data on the screen. We need to save it because memory is volatile and its contents would be lost once program terminated, so if we need some data again there are two ways one is retype via keyboard to assign it to particular variable, and other is regenerate it via programmatically both options are tedious. At such time it becomes necessary to store the data in a manner that can be later retrieved and displayed either in part or in whole. This medium is usually a ''file'' on the disk. Introduction to file Until now we have been using the functions such as scanf,printf, getch, putch etc to read and write data on the variable and arrays for storing data inside the programs. But this approach poses the following programs. 1. The data is lost when program terminated or variable goes out of scope. 2. Difficulty to use large volume of data. We can overcome these problems by storing data on secondary devices such as Har...

ENUMERATION

1.Enum is a collection of named integer constant means it's each element is assigned by integer value  2.It is declared with enum keyboard  #include<stdio.h> enum age { Rocky= 21 , Varsha= 19 , Afshana= 18 , Neeraj= 23 , Vandana= 24 , Jyoti= 16 }; int main () { enum age obj; obj=Vandana; /*age of vandana=24*/ printf( "The age of Vandana is %d" ,obj); } •Output  Age of vandana=24

UNION

Image
C Union is also like structure, i.e. collection of different data types which are grouped together. Each element in a union is called member. Union and structure both are same, except allocating memory for their members. Structure allocates storage space for each member separately. Whereas, Union allocates one common storage space for all its members. Syntax union tag_name { data type var_name1; data type var_name2; data type var_name3; }; Example union student { int id; char name[10]; char address[50]; }; Initializing and Declaring union variable union student data; union student data = {001,''AKKI'', ''mumbai''}; Accessing union members data.id data.name data.address 1.Union is approximately same as structure but it does not support multiple values simultaneously . 2.It supports only one value at a time. 3.It always supports last value. 4.In given example only makes will be true because marks is the last value assigned to it. #include<st...

STRUCTURE

1.INPUT NAME,ROLL NUMBERS AND MARKS OF STUDENTS AND PRINT USING STRUCTURE: #include<stdio.h> #include<string.h> struct Student { char name[ 200 ]; int rollno; float marks; }; int main () { struct Student obj; strcpy(obj.name= "Anil Singhania" ); obj.rollno= 205 ; obj.marks= 85.4 ; printf( "Name=%s\n" ,obj.name); printf( "Rollno=%d\n" ,obj.rollno); printf( "Marks=%f\n" ,obj.marks); •Output  Name=Anil Singhania Rollno=205; Marks=85.4           2.ADDITION PROGRAMME USING STRUCTURE:  #include<stdio.h> struct Arithmetic { int x; int y; int z; }; int main () { struct Arithmetic obj; obj.y= 20 ; obj.z= 50 ; obj.x=obj.y+obj.z; printf( "Add=%d" ,obj.x); } •OUTPUT  Add=70             3.USER INPUT STRUCTURE:  #include<stdio.h> struct Arithmetic { int x; int y; int z; }; int main () { struct Arithmetic obj; printf(...

STRING FUNCTION

  C supports a wide range of functions that manipulate null-terminated strings-    1.CHECK MOBILE NUMBER IS CORRECT                              OR NOT:  #include<stdio.h> #include<string.h> int main() { char mn[200]; printf("Enter mobile number\n"); gets(mn); if(strlen(mn)==10) printf("Number is correct"); else printf("Incorrect Number"); } •OUTPUT  Enter mobile number  9678513240 Mobile number is correct.     2.LOGIN PROGRAMME USING STRING: #include<stdio.h> #include<string.h> int main() { char u[200]="easy@gmail.com",p[200]="ani@789"; char u1[200],p1[200]; printf("Enter username\n"); gets(u1); printf("Enter password\n"); gets(p1); if(strcmp(u,u1)==0&&strcmp(p,p1)==0) printf("Login Successfully"); else printf("Wrong username or password"); } •Output  Enter username  Easy@gmail.com  Enter password  Sand@123 Login succe...