0% found this document useful (0 votes)
42 views60 pages

C Programs 1

C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views60 pages

C Programs 1

C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

S.

no Program Page no Date Remarks/signature

1 WAP TO FIND SUM OF TWO NUMBERS

2 WAP TO CALCULATE & DISPLAY ARES OF


CIRCLE.
WAP TO CONVER DEGREE CENTIGRADE TO
3 FAHRENHEIT.
WAP TO CALCULATE THE AREA & PERIMETER
4 OF RECTANGLE.
WAP TO DISPLAY ANY GIVEN NATURAL
5 NUMBER IS EVEN OR ODD.
WAP TO DISPLAY ANY GIVEN YEAR IS LEAP
6 YEAR OR NOT.
WAP TO DISPLAY THE LARGEST NUMBER
7 BETWEEN TWO NUMBERS
WAP TO DISPLAY THE LARGEST NUMBER
8 AMONG THREE NUMBERS.
WAP TO SWAP TWO NUMBERS WITHOUT
9 USING THIRD VARIABLE.
WAP TO DISPLAY FACTORIAL OF ANY GIVEN
10 NUMBER.
WAP TO DISPLAY ANY GIVEN NATUAL
11 NUMBER IS PRIME OR NOT.
WAP TO DISPLAY THE REVERSE OF ANY GIVEN
12 NATUAL NUMBER.
WAP TO DISPLAY THE SUM OF DIGITS OF ANY
13 GIVEN NATUAL NUMBER.
WAP TO DISPLAY ANY GIVEN NATUAL
14 NUMBER IS PALINDROME OR NOT.
WAP TO DISPLAY THE LARGEST & SMALLEST
15 NUMBER OF AN ARRAY.
WAP TO SEARCH THE NUMBER INTO AN
16 ARRAY USING LINEAR SEARCH.
WAP TO SEARCH THE NUMBER INTO AN
17 ARRAY USING BINARY SEARCH.
WAP TO SORT THE NUMBER OF AN ARRAY.
18
WAP TO DISPLAY THE SECOND & THIRD
19 LARGEST NUMBER OF AN ARRAY.
WAP TO DISPLAY THE TRANSPOSE OF 3X3
20 MATRIX.
WAP TO DISPLAY THE SUM OF TWO 3X3
21 MATRICES.
WAP TO DISPLAY THE PRODUCT OF TWO 3X3
22 MATRICES.
WAP TO DISPLAY THE REVERSE OF ANY GIVEN
23 STRING WITHOUT USING LIBRARY FUNCTION.
WAP TO CONCATINATE THE TWO STRINGS
24 WITHOUT USING LIBRARY FUNCTION.

2
WAP TO COMPARE THE TWO STRINGS ARE
25 IDENTACAL OR NOT WITHOUT USING LIBRARY
FUNCTION.
WAP TO CONVERT THE STRING INTO UPPER
26 CASE WITHOUT USING LIBRARY FUNCTION.
WAP TO CONVERT THE STRING INTO LOWER
27 CASE WITHOUT USING LIBRARY FUNCTION.
WAP TO COPY ONE STRING INTO ANOTHER
28 STRING WITHOUT USING LIBRARY FUNCTION.
WAP TO SWAP TWO NUMBERS USING CALL BY
29 REFERENCE.
WAP TO DISPLAY STUDENT RECORDS WITH
30 ROLL NUM, NAME, COURSE, AGE, & ADDRESS
USING STRUCTURE.
WAP TO DISPLAY 5 EMPLYOEES RECORDS
31 WITH EMP_ID, EMP_NAME, SALARY,
COMPANY, & ADDRESS USING STRUCTURE.
WAP TO DISPLAY 10 BOOKS RECORDS WITH
32 BOOK TITLE, AUTHOR NAME, PRICE, NO OF
PAGES & EDITION USING STRUCTURE.
A FILE NAMED "DATA" CONTAINS A SERIES OF
33 INTERGER NUMBERS A PROGRAM TO READ
THESE NUMBERS AND THEN WRITE ALL ODD
NUMBERS TO A FILE "ODD" AND ALL EVEN
NUMBERS TO A FILE CALLED "EVEN".
WAP TO COPY ONE FILE INTO ANOTHER FILE.
34
35 WAP TO READ THE DETAILS OF A STUDENT (
ROLL, NAME, FEE, DOB, & COURSE) AND THEN
PRINT IT ON THE SCREEN AS WELL AS WRITE IT
INTO A FILE.

3
1. WAP to find sum of two Numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(" Enter the First number = ");
scanf("%d",&a);
printf(" Enter the second number =");
scanf("%d",&b);
c = a + b;
printf("\n Sum of two number =%d",c);
getch();
}

Output:

4
2. WAP to calculate & Display area of circle.

#include<stdio.h>
#include<conio.h>
void main()
{
float r,area;
clrscr();
printf(" Enter the radius = ");
scanf("%f",&r);
area = 3.14*r*r;
printf("\n Area of circle =%f",area);
getch();
}
Output

5
3. WAP to conver degree centigrade to fahrenheit .

#include<stdio.h>
#include<conio.h>
void main()
{
float celsius,fahrenheit;
clrscr();
printf(" Enter the temp in celsius =");
scanf("%f", &celsius);
fahrenheit = (1.8 * celsius) + 32;
printf("\n the temp of celsius = %f",fahrenheit);
getch();
}
Output

6
4. WAP to calculate the area & perimeter of rectanlge .

#include<stdio.h>
#include<conio.h>
void main()
{
float l,b, area,perimeter;
clrscr();
printf("Enter the length =");
scanf("%f",&l);
printf("enter the breadth =");
scanf("%f",&b);
area = l * b;
perimeter = 2*(l+b);
printf("\n Area of rectangle =%f",area);
printf("\n Perimeter of rectangle =%f",perimeter );
getch();
}
Output

7
5. WAP to display any given natural number even or odd.

#include<stdio.h>

#include<conio.h>

void main()

int n;

clrscr();

printf(" Enter the number =");

scanf("%d",&n);

if(n%2==0)

printf("\n The number of even =%d",n);

else

printf("\n The number of odd =%d",n);

getch();

Output

8
6. WAP to display any year is leap year or not .

#include<stdio.h>

#include<conio.h>
void main()
{
int num;
clrscr();

printf(" Enter the leap year =");


scanf("%d",&num);
if(num % 4 == 0)
{
printf("\n The given year is aleap year =%d",num);

}
else
{
printf("\n the given year is not a leap year =%d",num);
}

getch();
}

Output

9
7. WAP to display the largest number between two number.

#include<stdio.h>

#include<conio.h>

void main()

int a,b;

clrscr();

printf(" Enter the first number =");

scanf("%d",&a);

printf(" Enter the second number =");

scanf("%d",&b);

if(a>b)

printf("\n a is the largest number =%d",a);

if(b>a)

printf("\n b is the largest number =%d",b);

else

printf("\n a is the largest number =%d",a);

getch();

10
Output

11
8.WAP to display the largest number among three number .

#include<stdio.h>

#include<conio.h>

int main()

int a,b,c;

clrscr();

printf("Enter the Ist , 2nd & 3rd number = ");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

if(a>c)

printf("\n a is largest number =%d",a);

else

printf("\n c is largest number =%d",c);

else

if(b>c)

printf("\n b is the largest number =%d",b);

else

printf("\n c is the largest number =%d",c);

getch();

Output

12
9. WAP to swap two numbers without using third number.

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf("Input value for x & y = ");
scanf("%d%d",&x,&y);
printf("Before swapping the value of x & y : %d %d",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("\n After swapping the value of x & y: %d %d",x,y);
getch();
}
Output

13
10. WAP to display factorial of any given number.

#include<stdio.h>
#include<conio.h>

void main()
{
int num,i=1,f=1;
clrscr();
printf("\n Enter the any number =");

scanf("%d",&num);
while(i<=num)
{
f=f*i;
i=i+1;

}
printf("\n The value of the factorial =%d",f);
getch();
}
Output

14
11. WAP to display any given natural number is prime or not.

#include<stdio.h>

#include<conio.h>

void main()

int n,i,f=0;

clrscr();

printf("\n Enter the number =");

scanf("%d",&n);

for(i=2;i<=n/2;i++)

if(n%i==0)

f=1;

break;

if(f==0)

printf("\n The num is prime");

else

printf("\n The is not prime number ");

getch();

15
Output

16
12. WAP to display the reverse of any given natural number.

#include<stdio.h>

#include<conio.h>

void main()

int n,r,rev=0;

clrscr();

printf("\n Enter the number =");

scanf("%d",&n);

while(n>0)

r=n%10;

rev=rev*10+r;

n=n/10;

printf("\n The reverse of number = %d",rev);

getch();

Output

17
13. WAP to display the sum of digits of any given natural number.

#include<stdio.h>
#include<conio.h>
void main()
{

int n,sum=0;
clrscr();
printf("\n Enter the number =");
scanf("%d",&n);
while(n!=0)
{
sum =sum +n%10;
n=n/10;
}
printf("\n The sum of digits of number = %d",sum);

getch();
}
Output

18
14. WAP to display any given natural number is paildrome or not.

#include<stdio.h>

#include<conio.h>

void main()

int n,i,m,rev=0;

clrscr();

printf("\n Enter the number =");

scanf("%d",&n);

m=n;

while(n>0)

i=n%10;

rev=rev*10+i;

n=n/10;

if(m==rev)

printf("\n The num is paildrome =%d",rev);

else

printf("\n The is not paildrome =%d ",rev);

getch();

Output

19
15. WAP to display the largest and smallest number of an array..

#include<stdio.h>

#include<conio.h>

void main()

int i, A[3],s,l;

clrscr();

for(i=0;i<4;i++)

printf("Enter the number into A=");

scanf("%d",&A[i]);

l=A[0];

s=A[0];

for(i=1;i<4;i++)

if(l<A[i])

l=A[i];

else if(s>A[i])

s=A[i];

printf("\n The largest num of A=%d",l);

printf("\n The smallest num of A=%d",s);

getch();

20
Output

21
16. WAP to search the number into an array using linear search.
#include<stdio.h>

#include<conio.h>

void main()

int i,n,A[10],f=0;

clrscr();

for(i=0;i<10;i++)

printf("enter the number =");

scanf("%d",&A[i]);

printf("enter the num to search =");

scanf("%d",&n);

for(i=0;i<10;i++)

if(n==A[i])

f=1;

break;

if(f==1)

printf("\n The num is searched successfully ");

printf("\n The position of num =%d",(i+1));

else

printf("\n the number is not search successfully ");

getch();

22
Output

23
17. WAP to search the number into an array using binear search.

#include<stdio.h>

#include<conio.h>
void main()
{
int i,n,A[10],beg,end,mid;
clrscr();

for(i=0;i<6;i++)
{
printf("enter the number =");
scanf("%d",&A[i]);
}

printf("enter the num to search =");


scanf("%d",&n);
beg=0;
end=9;
mid=(beg+end)/2;

while((beg<end) && (A[mid]!=n))


{
if(n>A[mid])
{
beg=mid+1;

}
else
{
end=mid-1;
}
mid=(beg+end)/2;

24
}
if(A[mid]==n)
{

printf("\n The num is searched successfully ");


}
else
{
printf("\n the number is not search successfully ");

}
getch();
}
Output

25
18. WAP to sort the number ofan array.

#include<stdio.h>

#include<conio.h>

void main()

int i,j,t,A[5];

clrscr();

for(i=0;i<5;i++)

printf("enter the num =");

scanf("%d",&A[i]);

for(i=0;i<5;i++)

for(j=j+1;j<5;j++)

if(A[i]>A[j])

t=A[i];

A[i]=A[j];

A[j]=t;

printf("\n The sorted num =\n");

for(i=0;i<5;i++)

printf(" %d ",A[i]);

getch();

26
Output

27
19.WAP to display the second and third largest number of an array.

#include<stdio.h>

#include<conio.h>

void main()

int n=0,i=0,l1=0,l2=0,temp=0,array[10];

clrscr();

printf("enter the size of the array \n");

scanf("%d",&n);

printf("enter the element \n");

for(i=0;i<n;i++)

scanf("%d",&array[i]);

printf("The array elements are :\n");

for(i=0;i<n;i++)

printf("%d\t",array[i]);

printf("\n");

l1=array[0];

l2=array[1];

if(l1<l2)

temp=l1;

l1=l2;

l2=temp;

for(i=2;i<n;i++)

if(array[i]>l1)

28
l2=l1;

l1=array[i];

else if(array[i]>l2 && array[i]!=l1)

l2=array[i];

printf("The second largest =%d\n",l1);

printf("The thrid Largest =%d\n",l2);

getch();

Output

29
20. WAP to display the transpose of 3*3 matrix.

#include<stdio.h>
#include<conio.h>

void main()
{
int i,j,A[3][3],B[3][3];
clrscr();
printf("enter 3*3 Matrix :");

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d", &A[i][j]);
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
B[i][j] = A[i][j];

}
}
printf("The transport of matrix =\n");
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
{
printf("%d ",B[i][j]);
}
printf("\n");

30
}
getch();

Output

31
21. WAP to display the sum oftwo 3*3 matrix.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,A[3][3],B[3][3],C[3][3];

clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("Enter the matrix A=");
scanf("%d",&A[i][j]);
}
}
for(i=0;i<3;i++)

{
for(j=0;j<3;j++)
{
printf("Enter the matrix B=");
scanf("%d",&B[i][j]);

}
}
printf("The of matrix A =\n");
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
{
printf("%d ",A[i][j]);

32
}
printf("\n");
}

printf("The of matrix B =\n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{

printf("%d ",B[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)

{
for(j=0;j<3;j++)
{
C[i][j]=A[i][j]+B[i][j];
}

}
printf("The Sum of matrix C =\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)

{
printf("%d ",C[i][j]);
}
printf("\n");
}
getch()

33
}
output

34
}

35
22. WAP to display the product of two 3*3 matrix.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,A[3][3],B[3][3],C[3][3];

clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{

printf("Enter the matrix A=");


scanf("%d",&A[i][j]);
}
}
for(i=0;i<3;i++)

{
for(j=0;j<3;j++)
{
printf("Enter the matrix B=");
scanf("%d",&B[i][j]);

}
}
printf("The of matrix A =\n");
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
{

36
printf("%d ",A[i][j]);
}
printf("\n");

}
printf("The of matrix B =\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)

{
printf("%d ",B[i][j]);
}
printf("\n");
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
C[i][j]=0;

for(int k=0;k<3;k++)
{
C[i][j]=C[i][j]+A[i][j]*B[i][j];
}
}

}
printf("The product of matrix C =\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{

37
printf("%d ",C[i][j]);
}
printf("\n");

}
getch();
}
Output

38
23.WAP to display the reverse of any given string without using
library function.
#include<stdio.h>

#include<conio.h>

void main()

char A[10];

int i=0,l=0;

clrscr();

printf("Enter the string =");

gets(A);

while(A[i]!='\0')

l++;

i++;

l=l-1;

printf("\n the reverse of string =");

while(i>=0)

printf("%c",A[i]);

i--;

getch();

Output

39
24.WAP to concatinate the two string without using library function.

#include<stdio.h>

#include<conio.h>

void main()

char A[10],B[10];

int i=0,j=0;

clrscr();

printf("Enter the 1st string =");

gets(A);

printf("Enter the 2nd string =");

gets(B);

while(A[i]!='\0')

i++;

while(B[j]!='\0')

A[i]=B[j];

i++;

j++;

A[i]='\0';

printf("\n the After concatnation string =");

puts(A);

getch();

Output

40
25.WAP to compare the two string are identacal or not without using library function.

#include<stdio.h>

#include<conio.h>

void main()

char A[10],B[10];

int i=0,f=0,l,m;

clrscr();

printf("Enter the 1st string =");

gets(A);

printf("Enter the 2nd string =");

gets(B);

l=strlen(A);

m=strlen(B);

if(l==m)

while(i<l)

if(A[i]==B[l])

i++;

else

break;

if(i==l)

f=1;

printf("the both string are same ");

41
}

if((f==0)&&(l>m))

printf("the both string are not equal string is greater than string ");

if((f==0)&&(l<m))

printf("the both are not same & string is greater than string ");

else if(f==0)

printf("\n the both string are not equal ");

getch();

Output

42
26.WAP to convert the string into upper case without library function.
#include<stdio.h>

#include<conio.h>

void main()

char A[10],B[10];

int i=0,j=0,l=0;

clrscr();

printf("enter the string =");

gets(A);

while(A[i]!='\0')

i++;

l++;

while(j<l)

if(A[j]>='a' && A[j]<='z')

B[j]=A[j]-32;

else

B[j]=A[j];

j++;

B[j]='\0';

printf("\n The string into upper case =");

puts(B);

getch();

43
Output

44
27.WAP to convert the string into lower case without library function.

#include<stdio.h>

#include<conio.h>

void main()

char A[10],B[10];

int i=0;

clrscr();

printf("enter the string =");

gets(A);

while(A[i]!='\0')

if(A[i]>='A' && A[i]<='Z')

B[i]=A[i]+32;

else

B[i]=A[i];

i++;

B[i]='\0';

printf("\n The string into lower case =");

puts(B);

getch();

Output

45
28.WAP tocopy one string into another string without library function.

#include<stdio.h>
#include<conio.h>
void main()
{
char A[10],B[10];

int i=0;
clrscr();
printf("enter the string =");
gets(A);
while(A[i]!='\0')

{
B[i]=A[i];
i++;
}
B[i]='\0';

printf("\n The string copied =");


puts(B);
getch();
}
Output

46
29. WAP to swap two numbers using call by reference.

#include<stdio.h>
#include<conio.h>
void swap(int *a , int *b);
void main()

{
int a,b;
clrscr();
printf("enter the value of a & b =");
scanf("%d%d",&a,&b);

swap(&a,&b);
printf("\n a=%d",a);
printf("\n b=%d",b);
getch();
}

void swap(int *x , int *y)


{
int t;
t=*x;
*x=*y;

*y=t;
}
Output

47
30. WAP to display student records with roll num,name,course,age,& address using structure..

#include<stdio.h>

#include<conio.h>

struct student

int roll_no;

char name[20];

char course[20];

int age;

char address[20];

};

void main()

struct student k;

clrscr();

printf("enter the student roll no =");

scanf("%d",&k.roll_no);

printf("enter the student name=");

scanf("%s",&k.name);

printf("enter the student course=");

scanf("%s",&k.course);

printf("enter the student age=");

scanf("%d",&k.age);

printf("enter the student address =");

scanf("%s",&k.address);

printf("\n The Records of a students =");

printf("\n Roll no =%d",k.roll_no);

printf("\n Name =%s",k.name);

printf("\n Course =%s",k.course);

printf("\n age =%d",k.age);

printf("\n Address =%s",k.address);

getch();

48
Output

49
31.WAP to display 5 employees records with EMP_ID,EMP_Name,Salary,company,&
address using structure…

#include<stdio.h>

#include<conio.h>

struct employee

int emp_id;

char name[20];

int salary;

char company[20];

char address[20];

};

void main()

struct employee A[10];

int i;

clrscr();

printf(" Enter the employee records =\n");

for(i=0;i<2;i++)

printf(" enter the Emp Id =");

scanf("%d",&A[i].emp_id);

printf("enter the Name =");

scanf("%s",&A[i].name);

printf(" enter the salary =");

scanf("%d",&A[i].salary);

printf(" enter the company =");

scanf("%s",&A[i].company);

printf("enter the address =");

scanf("%s",&A[i].address);

printf("\n the employees record =");

50
for(i=0;i<2;i++)

printf("\n ID =%d",A[i].emp_id);

printf("\n Name=%s",A[i].name);

printf("\n Salary =%d",A[i].salary);

printf("\n Company =%s",A[i].company);

printf("\n Address =%s",A[i].address);

getch();

Output

51
32. WAP to display 10 books record with bootitle,auther name,price,no.of
pageses,eddition using structure.

#include<stdio.h>

#include<conio.h>

struct book

char booktitle[20];

char authname[20];

int price;

int no_ofpages;

char ed[20];

};

void main()

struct book a[20];

int i;

clrscr();

printf("enter the book records \n");

for(i=0;i<2;i++)

printf("enter the booktitle=");

scanf("%s",&a[i].booktitle);

printf("enter the auther name=");

scanf("%s",&a[i].authname);

printf("enter price=");

scanf("%d",&a[i].price);

printf("enter page=");

scanf("%d",&a[i].no_ofpages);

printf("enter edition=");

scanf("%s",&a[i].ed);

printf("\n the book record=");

52
for(i=0;i<2;i++)

printf("\n book name=%s",a[i].booktitle);

printf("\n auther name=%s",a[i].authname);

printf("\n price =%d",a[i].price);

printf("\n page =%d",a[i].no_ofpages);

printf("\n edition =%s",a[i].ed);

getch();

Output

53
34.WAP a file Name DATA contains a series of integer numbers code a program to
read this number and then write all ODD numbers to a file to record and all even
number into and Even number into a file to be called number EVEN.

#include<stdio.h>

#include<conio.h>

void main()

FILE *fp1,*fp2,*fp3;

int i,n,m;

clrscr();

fp1=fopen("DATA","w");

if(fp1==NULL)

printf("the file data is not opened");

exit(0);

for(i=1;i<=3;i++)

printf("eneter the number=");

scanf("%d",&n);

putc(n,fp1);

fclose(fp1);

fp1=fopen("DATA","r");

fp2=fopen("ODD","w");

fp3=fopen("EVEN","w");

while(m=getc(fp1)!=EOF)

if(m<0)

break;

54
else if(m%2==0)

putc(m,fp3);

else

putc(m,fp2);

fclose(fp1);

fclose(fp2);

fclose(fp3);

fp2=fopen("ODD","r");

fp3=fopen("EVEN","r");

printf("\n the ODD number=");

while(m=getw(fp2)!=EOF)

printf("%d",m);

printf("\n the EVEN num=");

while((m=getw(fp3)!=EOF))

printf("%d",m);

fclose(fp2);

fclose(fp3);

getch();

55
Output

56
/* 34.WAP to copy one file to another file.*/

#include<stdio.h>

#include<conio.h>

void main()

FILE *fp1,*fp2;

char ch,file1[20],file2[20];

clrscr();

printf("enetr the file1 name=");

scanf("%s",&file1);

printf("enter the file2 name=");

scanf("%s",&file2);

fp1=fopen("file1","r");

fp2=fopen("file2","w");

if(fp1==NULL)

printf("The file is not opened");

exit(0);

if(fp2==NULL)

printf("the file2 is not opened");

exit(0);

while(ch=fgetc(fp1)!=EOF);

putc(ch,fp2);

printf("file1 is copied into file2");

fclose(fp1);

fclose(fp2);

getch();

57
}

Output

58
35. WAP to read the details of a student (roll,name,fee,dob,course)and then print it
on the screen as well as white into a file.

#include<stdio.h>

#include<conio.h>

struct student

int roll;

char name[20];

char fee[20];

char dob[30];

char course[10];

};

void main()

FILE *fp;

char filename[20];

struct student k[5];

int i;

clrscr();

printf("enter the file name =");

scanf("%s",&filename);

fp=fopen("filename","w");

if(fp==NULL)

printf("The file is not opened");

exit(0);

for(i=0;i<2;i++)

printf("enter the roll=");

scanf("%d",&k[i].roll);

printf("enter the name=");

59
scanf("%s",&k[i].name);

printf("enter the fee =");

scanf("%s",&k[i].fee);

printf("enter the dob =");

scanf("%s",k[i].dob);

printf("enter the course=");

scanf("%s",&k[i].course);

printf("\n the student records ...");

for(i=0;i<2;i++)

printf("\n Roll =%d",k[i].roll);

printf("\n name =%s",k[i].name);

printf("\n Fee =%s",k[i].fee);

printf("\n DOB =%s",k[i].dob);

printf("\n Course =%s",k[i].course);

for(i=0;i<2;i++)

fprintf(fp,"\n roll no =%d",k[i].roll);

fprintf(fp,"\n name =%s",k[i].name);

fprintf(fp,"\n fee =%s",k[i].fee);

fprintf(fp,"\n dob =%s",k[i].dob);

fprintf(fp,"\n course =%s",k[i].course);

fclose(fp);

getch();

60
Output

61

You might also like