Practical File of C Language

RAJWANT  KAUR
RAJWANT KAURMBA en HOME

Practical File of C Language

1
1. //Wap to print simple message.
#include<stdio.h>
#include<conio.h>
void main()
{
printf(" Get Well Soon");
clrscr();
getch();
}
Output:-
2
2. //Wap to add two numbers .
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter the values of a and b");
scanf("%d%d",&a,&b);
c=a+b;
printf("sum=%d",c);
getch();
}
Output:-
3
3. //Wap to calculate average of 5 numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,avg;
clrscr();
printf("enter the values of a, b, c, d, and e");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
avg=(a+b+c+d+e)/5;
printf("avg=%d",avg);
getch();
}
Output:-
4
4. //Wap to multiply three numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=8,c=6,d;
clrscr();
d=a*b*c;
printf("mul=%d",d);
getch();
}
Output:-
5
5. //Wap to print area of a circle.
#include<stdio.h>
#include<conio.h>
void main()
{
int r;
float pie=3.14;
float area;
printf("Enter the value of r");
scanf("%d",&r);
area=(pie*r*r);
printf("Area=%f",area);
getch();
}
Output:-
6
6. //Wap to print the biggestof three numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the values of a,b,and c");
scanf("%d%d%d",&a,&b,&c);
if (a>b&&a>c)
{
printf(" A is Biggest");
}
if (b>a&&b>c)
{
printf("Bis Biggest");
}
if (c>a&&c>b)
{
printf("Cis Biggest");
}
getch();
}
7
Output:-
8
7. //Wap to check givennumber is even or odd.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter the value of a");
scanf("%d",&a);
if(a%2==0)
{
printf("Number is Even");
}
else
{
printf("Number is Odd");
}
getch();
}
Output:-
9
8. //Wap to check givennumber is positive or negative.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter the value of a");
scanf("%d",&a);
if (a>0)
{
printf("Number is Positive");
}
else
{
printf("Number is Negative");
}
getch();
}
10
9. //Wap to check givenyear is leap year or not?
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Enter tha value of a");
scanf("%d",&a);
if (a%4==0)
{
printf("This year is Leap Year");
}
else
{
printf("This is not Leap Year");
}
getch();
}
Output:-
11
10. //Wap to print the name of day according to user
choice.
#include<stdio.h>
#include<conio.h>
void main()
{
int day;
clrscr();
printf("Enter the value for day 1 to 7");
scanf("%d",&day);
if (day==1)
{
printf("n Monday");
}
else if (day==2)
{
printf("n Tuesday");
}
else if (day==3)
{
printf("n Wednesday");
}
else if (day==4)
{
12
printf("n Thursday");
}
else if (day==5)
{
printf("n Friday");
}
else if (day==6)
{
printf("n Saturday");
}
else if (day==7)
{
printf("n Sunday");
}
else
{
printf("PleaseEnter Correct Value");
}
getch();
}
13
11. //Wap to print the name of month.
#include<stdio.h>
#include<conio.h>
void main()
{
int month;
clrscr();
printf("Enter the value for month 1 to 12");
scanf("%d",&month);
switch (month)
{
case 1:
printf("January");
break;
case 2:
printf("Febuary");
break;
case 3:
printf("March");
break;
case 4:
printf("April");
break;
case 5:
14
printf("May");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf("August");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf("November");
break;
case 12:
printf("December");
break;
default:
15
printf("PleaseEnter Correct Value");
break;
}
getch();
}
Output:-
16
12. //Wap to print 1 to 10 no by while loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while(i<=10)
{
printf("n %d",i);
i++;
}
getch();
}
Output:-
17
13. //Wap to print 1 to 10 Numbers by using do while.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
do
{
printf("n %d",i);
i++;
}while(i<=10);
getch();
}
Output:-
18
14. //Wap to print 1 to 10 by using for loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("n %d",i);
}
getch();
}
Output:-
19
15. //Wap to calculate factorial of a given number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,fact=1;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
fact=fact*i;
}
printf("Factorialis=%d",fact);
getch();
}
Output:-
20
16. //Wap to print the fibonacci series.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a=0,b=1,c;
clrscr();
printf("Enter the term of fibonacci series");
scanf("%d",&n);
printf("%d%d",a,b);
for(i=1;i<n;i++)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
getch();
}
Output:-
21
17. //Wap to print the table of given no.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf("Enter a Number");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
printf("n %d*%d=%d",n,i,n*i);
}
getch();
}
Output:-
22
18. //Wap to print reverse of a number.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,n,rev=0,rem;
clrscr();
printf("Enter the Number");
scanf("%d",&num);
n=num;
while(n!=0)
{
rem=n%10;
n=n/10;
rev=rev*(10+rem);
}
printf("Old Number=%d",num);
printf("Reversed NO=%d",rev);
getch();
}
Output:-
23
19. //Wap to print given number is armstrong or not?
#include<stdio.h>
#include<conio.h>
void main()
{
int num,n,rem,sum=0;
clrscr();
printf("Enter a Number");
scanf("%d",&num);
n=num;
while(n!=0)
{
rem=n%10;
sum=sum+(rem*rem*rem);
n=n/10;
}
if (sum==num)
{
printf("n Number is Armstrong");
}
else
{
printf("n Number is not Armstrong");
}
24
getch();
}
Output:-
25
20. //Wap to print odd numbers between 1 to 50.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
while(i<=50)
{
if(i%2!=0)
printf("n %d",i);
i++;
}
getch();
}
Output:-
26
21. //Wap to check given number is palindrome or not?
#include<stdio.h>
#include<conio.h>
void main()
{
int n,rem,rev=0,num;
clrscr();
printf("Enter a Number");
scanf("%d",&n);
num=n;
while(n!=0)
{
rem=n%10;
n=n/10;
rev=((rev*10)+rem);
}
if(num==rev)
{
printf("Entered Number is palindrome");
}
else
{
printf("Entered Number is not Palindrome");
}
27
getch();
}
Output:-
28
22. //Wap to add two numbers using Functions.
#include<stdio.h>
#include<conio.h>
int sum(int,int);
void main()
{
int a,b,c;
printf("enter the values of a and b");
scanf("%d%d",&a,&b);
c=sum(a,b);
printf("sum=%d",c);
getch();
}
int sum(intx,int y)
{
int z;
z=x+y;
return z;
}
Output:-
29
23. //Wap to calculate the factorial of given number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,result;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
result=fact(n);
printf("factorial=%d",result);
getch();
}
int fact(int x)
{
if (x==0)
{
return(1);
}
else
{
return(x*fact(x-1));
}
}
30
Output:-
31
24. //Wap to print the fibonacci series.
#include<stdio.h>
#include<conio.h>
int fib(int m);
void main()
{
int n,i;
clrscr();
printf("Enter the term of fibonacci series");
scanf("%d",&n);
printf("n0");
for(i=1;i<=n;i++)
printf("n &d",fib(i));
getch();
}
int fib(int m)
{
static int a=0,b=1;
int c;
return(0);
if(m==1)
return(1);
else
{
32
c=a+b;
a=b;
b=c;
return(c);
}
Output:-
33
25. //Wap to calculate simple interest.
#include<stdio.h>
#include<conio.h>
void main()
{
int p,t,r;
int splint;
clrscr();
printf("Enter the value of p r and t");
scanf("%d%d%d",&p,&r,&t);
splint=(p*r*t/100);
printf("Splint=%d",splint);
getch();
}
Output:-
34
26. //Wap to show concept of function no argument
and with return.
#include<stdio.h>
#include<conio.h>
int mul();
void main()
{
int result;
result =mul();
printf("Multiplication=%d",result);
getch();
}
int mul()
{
int a,b,c;
printf("Enter the value of a and b");
scanf("%d%d",&a,&b);
c=a*b;
return c;
}
35
27. //Wap to show the concept of function with
argument and NO return.
#include<stdio.h>
#include<conio.h>
void sub(int,int);
void main()
{
int a,b;
clrscr();
printf("Enter the value of a and b");
scanf("%d%d",&a,&b);
sub(a,b);
getch();
}
void sub(intx,int y)
{
int z; z=x-y;
printf("Result=%d",z);
}
Output:-
36
28.//Wapto show concept of function with no argument
no return
#include<stdio.h>
#include<conio.h>
void display();
void programinfo();
void main()
{
clrscr();
display();
programinfo();
display();
getch();
}
void display()
{
int i;
for(i=1;i<=20;i++)
printf("*");
printf("n");
}
void programinfo()
{
printf(" No ArgumentNO Return n");
37
}
Output:-
38
29. //Wap to swap two numbers using call by value.
#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int a,b;
clrscr();
printf("Enter the value of a and b");
scanf("%d%d",&a,&b);
swap(a,b);
getch();
}
void swap(intx,int y)
{
int z;
z=x; x=y; y=z;
printf("%d%d",x,y);
}
Output:-
39
30. //Wap to swap two no by call by reference.
#inclu30.de<stdio.h>
#include<conio.h>
void swap(int*,int *);
void main()
{
int a,b;
clrscr();
printf("Enter the value of a and b");
scanf("%d%d",&a,&b);
swap(&a,&b);
getch();
}
void swap(int*x, int *y)
{
int z; z=*x; *x=*y; *y=z;
printf("%d %d",*x,*y);
}
Output:-
40
31. //Wap to print input elements using One-D array.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i;
printf("Enter Array Size");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the value of Elements %d",i);
scanf("%d",&a[i]);
}
printf("Array Elemnets are");
for(i=0;i<n;i++)
{
printf("n %d",a[i]);
getch();
}
Output:-
41
32. //Wap to find the maximum value fromarray.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,n,max;
printf("Enter the array size");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("n Enter the values of elements %d",i);
scanf("%d",&a[i]);
}
max=a[50];
for(i=0;i<n;i++)
{
if(max<a[i])
{
max=a[i];
}
}
printf("Maximumvalue=%d",max);
getch()
}
42
Output:-
43
33. //Wap to find the minimum value fromarray.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,n,min;
printf("Enter the array size");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("n Enter the values of elements %d",i);
scanf("%d",&a[i]);
}
min=a[0];
for(i=0;i<n;i++)
{
if(min>a[i])
{
min=a[i];
}
}
printf("Minimumvalue=%d",min);
getch();
}
44
Output:-
45
34. //Wap to print the sum of all array elements.
#include<stdio.h>
#include<conio.h>
void main()
{
int s[50],i,n,sum=0;
clrscr();
printf("Enter the array size");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("n Enter sum of student %d",i);
scanf("%d",&s[i]);
sum=sum+s[i];
}
{
printf("Sumof Student=%d",sum);
}
Output:-
46
35. //Wap to print input elements using Two-D array.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],j,i,r,c;
clrscr();
printf("Enter row and column size");
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Enter the value of Elements %d%d:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Array Elemnets are");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("n %d",a[i][j]);
}
47
printf("n");
}
getch();
}
Output:-
48
36. //Wap to add two matrices.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5];
int i,j,r,col;
clrscr();
printf("Enter the row and column size");
scanf("%d%d",&r,&col);
printf("n Enter the values of firstmatrix");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&a[i][j]);
}
}
printf("n Enter the values of second matrix");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
49
{
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=0;
c[i][j]=a[i][j]+b[i][j];
}
}
printf("n After Addition n");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
printf("%dt",c[i][j]);
}
printf("n");
}
getch();
}
50
Output:-
51
37. //Wap to multiply two matrices.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5];
int i,j,r,col;
clrscr();
printf("Enter the row and column size");
scanf("%d%d",&r,&col);
printf("n Enter the values of firstmatrix");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&a[i][j]);
}
}
printf("n Enter the values of second matrix");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
52
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=0;
c[i][j]=a[i][j]*b[i][j];
}
}
printf("n After Multiplication n");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
printf("%dt",c[i][j]);
}
printf("nn");
}
getch();
}
53
Output:-
54
38. //Wap to subtract two matrices.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5];
int i,j,r,col;
clrscr();
printf("Enter the row and column size");
scanf("%d%d",&r,&col);
printf("n Enter the values of firstmatrix");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&a[i][j]);
}
}
printf("n Enter the values of second matrix");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
55
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=0;
c[i][j]=a[i][j]-b[i][j];
}
}
printf("n After Subtraction n");
for(i=0;i<r;i++)
{
for(j=0;j<col;j++)
{
printf("%dt",c[i][j]);
}
printf("n");
}
getch();
}
56
Output:-
57
39. //Wap to Transpose a matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],i,j,r,c;
clrscr();
printf("Enter the row and column size");
scanf("%d%d",&r,&c);
printf("n Enter the values of firstmatrix");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&a[i][j]);
}
}
printf("n After Transposen");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%dt",a[i][j]);
58
}
printf("n");
}
getch();
}
Output:-
59
40. //Wap to print diagonal elements of a matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],i,j,r,c;
clrscr();
printf("Enter the row and column size");
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&a[i][j]);
}
}
printf("n Diagonal Elements are n");
for(i=0;i<j;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
{
60
printf("%dt",a[i][j]);
}
}
}
getch();
}
Output:-
61
41. //Wap to print sum of diagonal elements of a
matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],i,j,r,c,sum=0;
clrscr();
printf("Enter the row and column size");
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("n Enter the values of elements %d%d",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j)
{
62
sum+=a[i][j];
}
}
printf("n Sum of DiagonalElements are=%d",sum);
getch();
}
63
42. //Wap to calculate % in four subjects And show
rollno of students.
#include<stdio.h>
#include<conio.h>
structstudent
{
int rollno;
float sub1,sub2,sub3,sub4,per;
};
void main()
{
struct students1;
clrscr();
printf("Enter the info for students");
printf("n Enter the roll no for student:");
scanf("%d",&s1.rollno);
printf("Enter the marks for sub1,sub2,sub3,sub4");
scanf("%f%f%f%f",&s1.sub1,&s1.sub2,&s1.sub3,&s1.sub4);
s1.per=(s1.sub1+s1.sub2+s1.sub3+s1.sub4)/400*100;
printf("Info for student");
printf("n Roll no of Student=%d",s1.rollno);
printf("n Percentage of student=%f",s1.per);
getch();
64
}
Output:-
65
43. //Wap to print record of a school student.
#include<stdio.h>
#include<conio.h>
structstudent
{
int rollno;
int age;
char name;
float marks,sub1,sub2,per;
};
void main()
{
struct students1;
clrscr();
printf("Enter the info for students");
printf("n Enter the Name of student:");
scanf("%s",&s1.name);
printf("n Enter the roll no for student:");
scanf("%d",&s1.rollno);
printf("Enter the Age of student:");
scanf("%d",&s1.age);
printf("Enter the marks for sub1,sub2");
scanf("%f%f",&s1.sub1,&s1.sub2);
66
s1.per=(s1.sub1+s1.sub2)/200*100;
printf("Info for student");
printf("n Name of student %s",s1.name);
printf("n Roll no of Student=%d",s1.rollno);
printf("n Age of student:%d",s1.age);
printf("n Marks of sub1 and sub2 of student:%f %f",s1.sub1,s1.sub2);
printf("n Percentage of student=%f",s1.per);
getch();
}
Output:-
67
44. //Wap to print record of students using union.
#include<stdio.h>
#include<conio.h>
union student
{
int rollno;
char name[20];
int age;
float marks; } s;
void main() {
printf("Enter RollNo of Student :");
scanf("%d",&s.rollno);
printf("Enter the age of student :");
scanf("%d",&s.age);
printf("Enter the name of student:");
scanf("%s",&s.name);
printf("Enter the marks of student :");
scanf("%f",&s.marks);
printf("n RollNo=%d",s.rollno);
printf("n age=%d",s.age);
printf("n Name=%s",s.name);
printf("n marks=%f",s.marks);
getch();
}
68
45. //Wap to print address & value of variable and
address of pointer variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int * ptr;
int a=10;
clrscr();
ptr=&a;
printf("n %d",a);
scanf("%ld",&ptr);
printf("%ld",*ptr);
printf("n %ld",*ptr);
printf("n %ld",&a);
getch();
}
Output:-
69
46. //Wap to show the concept of pointer to pointer.
#include<stdio.h>
#include<conio.h>
void main()
{
int ** ptr;
int * p;
int a=10;
clrscr();
p=&a;
ptr=&p;
printf("n Value of a=%d",a);
printf("n Address of p=%ld",&p);
printf("n Value of p=%ld",p);
printf("n Content of a through p=%d",*p);
printf("n Address of p through ptr=%ld",ptr);
printf("n Content of a through ptr=%d",**ptr);
getch();
}
70
47. //Wap to show use of auto variable.
#include<stdio.h>
#include<conio.h>
void func1();
void main()
{
func1();
func1();
}
void func1()
{
auto int i=2;
printf("%dn",i);
i=i+2;
getch();
}
Output:-
71
48. //Wap to show use of static variable.
#include<stdio.h>
#include<conio.h>
int func1();
int func2();
main()
{
static int i=1;
printf("%d",i);
printf("n%d",func1());
printf("n%d",func2()); }
int func1() {
static int i;
i=i+2;
return(i); }
int func2()
{
static int i;
i=i+3;
return(i);
getch(); }
Output:-
72
49. //Wap to show use of external variable.
#include<stdio.h>
#include<conio.h>
int i=1;
int func1();
int func2();
void main()
{
printf("%d",i);
printf("n%d",func1());
printf("n%d",func2());
}
int func1()
{
i=i+10;
return(i);
}
int func2()
{
i=i+20;
return(i);
getch();
}
73
Output:---
74
50. //Wap to enter a mixed data into a file.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE*fp;
int rollno;
char name[20];
float marks;
fp=fopen("stud.txt","w");
clrscr();
if(fp==NULL)
{
printf("Cannotopen file");
}
printf("Enter student name,rollno,marks");
scanf("%s %d %f",name,&rollno,&marks);
fprintf(fp,"%s %d %f",name,rollno,marks);
fclose(fp);
getch();
}
75
Output:-
Output:-
76
51. //Wap to read a mixed data froma file.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE*fp;
int rollno;
char name[20];
float marks;
fp=fopen("stud.txt","r");
clrscr();
if(fp==NULL)
{
printf("Cannotopen file");
}
while(fscanf(fp,"%s %d %f",name,&rollno,&marks)!=EOF)
{
printf("%s %d %f",name,rollno,marks); }
fclose(fp);
getch(); }
Output
77
52. //Wap to enter a string data into a file.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE*fp;
char s[80];
fp=fopen("xyz.txt","w");
if(fp==NULL)
{
printf("Cannotopen file");
}
printf("Enter string data and press enter");
while((strlen(gets(s))>0))
{
fputs(s,fp);
fputs("n",fp);
}
close(fp);
}
78
Output:-
Output:-
79
53. //Wap to read a string data from a file.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE*fp;
char s[80];
clrscr();
fp=fopen("xyz.txt","r");
if(fp==NULL)
{
printf("Cannotopen file");
}
while(fgets(s,80,fp)!=NULL)
puts(s);
fclose(fp);
getch();
}
Output:-
80
54. //Wap to write integer into a file.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE*fp;
int n;
fp=fopen("raj.txt","w");
clrscr();
if(fp==NULL)
{
printf("Cannotopen file");
}
printf("Enter any integar value");
scanf("%d",&n);
putw(n,fp);
fclose(fp);
getch();
}
81
Output:-
Output:-
82
55. //Wap to read integer into a file.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE*fp;
int n;
fp=fopen("raj.txt","w");
clrscr();
if(fp==NULL)
{
printf("Cannotopen file");
}
while((n=getw(fp))!=EOF)
{
printf("%d",n);
}
fclose(fp);
getch(); }
Output:-

Recomendados

Data Structures Using C Practical File por
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
6.1K vistas82 diapositivas
Strings por
StringsStrings
StringsMitali Chugh
5.6K vistas24 diapositivas
C programs por
C programsC programs
C programsMinu S
8.5K vistas181 diapositivas
C string por
C stringC string
C stringUniversity of Potsdam
4.6K vistas22 diapositivas
C lab-programs por
C lab-programsC lab-programs
C lab-programsTony Kurishingal
9.1K vistas74 diapositivas
Object Oriented Programming Using C++ Practical File por
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileHarjinder Singh
14.9K vistas130 diapositivas

Más contenido relacionado

La actualidad más candente

Pointers in C Programming por
Pointers in C ProgrammingPointers in C Programming
Pointers in C ProgrammingJasleen Kaur (Chandigarh University)
34.9K vistas26 diapositivas
File in C language por
File in C languageFile in C language
File in C languageManash Kumar Mondal
909 vistas41 diapositivas
Polymorphism in c++(ppt) por
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Sanjit Shaw
13.8K vistas12 diapositivas
Functions in c por
Functions in cFunctions in c
Functions in csunila tharagaturi
1.5K vistas42 diapositivas
Structure in C por
Structure in CStructure in C
Structure in CKamal Acharya
35.3K vistas50 diapositivas
Pointer in c por
Pointer in cPointer in c
Pointer in clavanya marichamy
15.3K vistas14 diapositivas

La actualidad más candente(20)

Polymorphism in c++(ppt) por Sanjit Shaw
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
Sanjit Shaw13.8K vistas
Two dimensional arrays por Neeru Mittal
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal9.9K vistas
Oops practical file por Ankit Dixit
Oops practical fileOops practical file
Oops practical file
Ankit Dixit8.2K vistas
Character Array and String por Tasnima Hamid
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid958 vistas
GE8151 Problem Solving and Python Programming por Muthu Vinayagam
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
Muthu Vinayagam1.8K vistas
Class and object in C++ por rprajat007
Class and object in C++Class and object in C++
Class and object in C++
rprajat00720.7K vistas
C Structures and Unions por Dhrumil Patel
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel7.5K vistas
Manipulators in c++ por Ashok Raj
Manipulators in c++Manipulators in c++
Manipulators in c++
Ashok Raj672 vistas
Unit 4 python -list methods por narmadhakin
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin10.5K vistas
RECURSION IN C por v_jk
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk14K vistas

Similar a Practical File of C Language

C lab manaual por
C lab manaualC lab manaual
C lab manaualmanoj11manu
1.9K vistas36 diapositivas
C basics por
C basicsC basics
C basicsMSc CST
322 vistas25 diapositivas
Practical write a c program to reverse a given number por
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
9.9K vistas98 diapositivas
Practical write a c program to reverse a given number por
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
2.4K vistas104 diapositivas
Hargun por
HargunHargun
HargunMukund Trivedi
501 vistas24 diapositivas
Computer programming subject notes. Quick easy notes for C Programming.Cheat ... por
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...DR B.Surendiran .
1.8K vistas4 diapositivas

Similar a Practical File of C Language(20)

C lab manaual por manoj11manu
C lab manaualC lab manaual
C lab manaual
manoj11manu1.9K vistas
C basics por MSc CST
C basicsC basics
C basics
MSc CST322 vistas
Practical write a c program to reverse a given number por Mainak Sasmal
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal9.9K vistas
Practical write a c program to reverse a given number por Mainak Sasmal
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal2.4K vistas
Computer programming subject notes. Quick easy notes for C Programming.Cheat ... por DR B.Surendiran .
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .1.8K vistas
Best C Programming Solution por yogini sharma
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
yogini sharma610 vistas
Data Structure using C por Bilal Mirza
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza914 vistas
Simple C programs por ab11cs001
Simple C programsSimple C programs
Simple C programs
ab11cs0013.1K vistas
Basic c programs updated on 31.8.2020 por vrgokila
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila147 vistas
SaraPIC por Sara Sahu
SaraPICSaraPIC
SaraPIC
Sara Sahu549 vistas
LET US C (5th EDITION) CHAPTER 2 ANSWERS por KavyaSharma65
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65574 vistas
'C' language notes (a.p) por Ashishchinu
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
Ashishchinu6.2K vistas

Más de RAJWANT KAUR

Case Study on Coca Cola Company por
Case Study on Coca Cola CompanyCase Study on Coca Cola Company
Case Study on Coca Cola CompanyRAJWANT KAUR
58.7K vistas19 diapositivas
Case study on lg’s life good por
Case study on lg’s life goodCase study on lg’s life good
Case study on lg’s life goodRAJWANT KAUR
931 vistas14 diapositivas
Case study on LG (Life Good) por
Case study on LG (Life Good)Case study on LG (Life Good)
Case study on LG (Life Good)RAJWANT KAUR
9.1K vistas14 diapositivas
research project report on challenges faced by working women in private sect... por
research project report on challenges faced by  working women in private sect...research project report on challenges faced by  working women in private sect...
research project report on challenges faced by working women in private sect...RAJWANT KAUR
17.2K vistas53 diapositivas
Practical file on web technology(html) por
Practical file on web technology(html)Practical file on web technology(html)
Practical file on web technology(html)RAJWANT KAUR
14.4K vistas58 diapositivas
SOCIAL CLASS por
SOCIAL CLASSSOCIAL CLASS
SOCIAL CLASSRAJWANT KAUR
1.7K vistas36 diapositivas

Más de RAJWANT KAUR(10)

Case Study on Coca Cola Company por RAJWANT KAUR
Case Study on Coca Cola CompanyCase Study on Coca Cola Company
Case Study on Coca Cola Company
RAJWANT KAUR58.7K vistas
Case study on lg’s life good por RAJWANT KAUR
Case study on lg’s life goodCase study on lg’s life good
Case study on lg’s life good
RAJWANT KAUR931 vistas
Case study on LG (Life Good) por RAJWANT KAUR
Case study on LG (Life Good)Case study on LG (Life Good)
Case study on LG (Life Good)
RAJWANT KAUR9.1K vistas
research project report on challenges faced by working women in private sect... por RAJWANT KAUR
research project report on challenges faced by  working women in private sect...research project report on challenges faced by  working women in private sect...
research project report on challenges faced by working women in private sect...
RAJWANT KAUR17.2K vistas
Practical file on web technology(html) por RAJWANT KAUR
Practical file on web technology(html)Practical file on web technology(html)
Practical file on web technology(html)
RAJWANT KAUR14.4K vistas
Summer Training Report on Eastman Industries LTD. por RAJWANT KAUR
Summer Training Report on Eastman Industries LTD.Summer Training Report on Eastman Industries LTD.
Summer Training Report on Eastman Industries LTD.
RAJWANT KAUR2.3K vistas
Leadership advice by rajwant kaur por RAJWANT KAUR
Leadership advice by rajwant kaurLeadership advice by rajwant kaur
Leadership advice by rajwant kaur
RAJWANT KAUR430 vistas
Summer Training Report on G.S Radiators Ltd. Ludhiana (Punjab) por RAJWANT KAUR
Summer Training Report on G.S Radiators Ltd. Ludhiana (Punjab)Summer Training Report on G.S Radiators Ltd. Ludhiana (Punjab)
Summer Training Report on G.S Radiators Ltd. Ludhiana (Punjab)
RAJWANT KAUR3.5K vistas
ADVERTISEMENT TYPES & AD AGENICIES por RAJWANT KAUR
ADVERTISEMENT TYPES & AD AGENICIESADVERTISEMENT TYPES & AD AGENICIES
ADVERTISEMENT TYPES & AD AGENICIES
RAJWANT KAUR2.9K vistas

Último

Education and Diversity.pptx por
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptxDrHafizKosar
177 vistas16 diapositivas
Drama KS5 Breakdown por
Drama KS5 BreakdownDrama KS5 Breakdown
Drama KS5 BreakdownWestHatch
87 vistas2 diapositivas
On Killing a Tree.pptx por
On Killing a Tree.pptxOn Killing a Tree.pptx
On Killing a Tree.pptxAncyTEnglish
66 vistas11 diapositivas
Sociology KS5 por
Sociology KS5Sociology KS5
Sociology KS5WestHatch
76 vistas23 diapositivas
Use of Probiotics in Aquaculture.pptx por
Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptxAKSHAY MANDAL
104 vistas15 diapositivas
Classification of crude drugs.pptx por
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptxGayatriPatra14
92 vistas13 diapositivas

Último(20)

Education and Diversity.pptx por DrHafizKosar
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptx
DrHafizKosar177 vistas
Drama KS5 Breakdown por WestHatch
Drama KS5 BreakdownDrama KS5 Breakdown
Drama KS5 Breakdown
WestHatch87 vistas
On Killing a Tree.pptx por AncyTEnglish
On Killing a Tree.pptxOn Killing a Tree.pptx
On Killing a Tree.pptx
AncyTEnglish66 vistas
Sociology KS5 por WestHatch
Sociology KS5Sociology KS5
Sociology KS5
WestHatch76 vistas
Use of Probiotics in Aquaculture.pptx por AKSHAY MANDAL
Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptx
AKSHAY MANDAL104 vistas
Classification of crude drugs.pptx por GayatriPatra14
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra1492 vistas
Psychology KS4 por WestHatch
Psychology KS4Psychology KS4
Psychology KS4
WestHatch90 vistas
AUDIENCE - BANDURA.pptx por iammrhaywood
AUDIENCE - BANDURA.pptxAUDIENCE - BANDURA.pptx
AUDIENCE - BANDURA.pptx
iammrhaywood89 vistas
How to empty an One2many field in Odoo por Celine George
How to empty an One2many field in OdooHow to empty an One2many field in Odoo
How to empty an One2many field in Odoo
Celine George72 vistas
Psychology KS5 por WestHatch
Psychology KS5Psychology KS5
Psychology KS5
WestHatch103 vistas
REPRESENTATION - GAUNTLET.pptx por iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood107 vistas
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant... por Ms. Pooja Bhandare
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Ms. Pooja Bhandare109 vistas
Dance KS5 Breakdown por WestHatch
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 Breakdown
WestHatch86 vistas
Create a Structure in VBNet.pptx por Breach_P
Create a Structure in VBNet.pptxCreate a Structure in VBNet.pptx
Create a Structure in VBNet.pptx
Breach_P75 vistas
CUNY IT Picciano.pptx por apicciano
CUNY IT Picciano.pptxCUNY IT Picciano.pptx
CUNY IT Picciano.pptx
apicciano54 vistas

Practical File of C Language

  • 1. 1 1. //Wap to print simple message. #include<stdio.h> #include<conio.h> void main() { printf(" Get Well Soon"); clrscr(); getch(); } Output:-
  • 2. 2 2. //Wap to add two numbers . #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("enter the values of a and b"); scanf("%d%d",&a,&b); c=a+b; printf("sum=%d",c); getch(); } Output:-
  • 3. 3 3. //Wap to calculate average of 5 numbers. #include<stdio.h> #include<conio.h> void main() { int a,b,c,d,e,avg; clrscr(); printf("enter the values of a, b, c, d, and e"); scanf("%d%d%d%d%d",&a,&b,&c,&d,&e); avg=(a+b+c+d+e)/5; printf("avg=%d",avg); getch(); } Output:-
  • 4. 4 4. //Wap to multiply three numbers #include<stdio.h> #include<conio.h> void main() { int a=5,b=8,c=6,d; clrscr(); d=a*b*c; printf("mul=%d",d); getch(); } Output:-
  • 5. 5 5. //Wap to print area of a circle. #include<stdio.h> #include<conio.h> void main() { int r; float pie=3.14; float area; printf("Enter the value of r"); scanf("%d",&r); area=(pie*r*r); printf("Area=%f",area); getch(); } Output:-
  • 6. 6 6. //Wap to print the biggestof three numbers #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("Enter the values of a,b,and c"); scanf("%d%d%d",&a,&b,&c); if (a>b&&a>c) { printf(" A is Biggest"); } if (b>a&&b>c) { printf("Bis Biggest"); } if (c>a&&c>b) { printf("Cis Biggest"); } getch(); }
  • 8. 8 7. //Wap to check givennumber is even or odd. #include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("enter the value of a"); scanf("%d",&a); if(a%2==0) { printf("Number is Even"); } else { printf("Number is Odd"); } getch(); } Output:-
  • 9. 9 8. //Wap to check givennumber is positive or negative. #include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("enter the value of a"); scanf("%d",&a); if (a>0) { printf("Number is Positive"); } else { printf("Number is Negative"); } getch(); }
  • 10. 10 9. //Wap to check givenyear is leap year or not? #include<stdio.h> #include<conio.h> void main() { int a; printf("Enter tha value of a"); scanf("%d",&a); if (a%4==0) { printf("This year is Leap Year"); } else { printf("This is not Leap Year"); } getch(); } Output:-
  • 11. 11 10. //Wap to print the name of day according to user choice. #include<stdio.h> #include<conio.h> void main() { int day; clrscr(); printf("Enter the value for day 1 to 7"); scanf("%d",&day); if (day==1) { printf("n Monday"); } else if (day==2) { printf("n Tuesday"); } else if (day==3) { printf("n Wednesday"); } else if (day==4) {
  • 12. 12 printf("n Thursday"); } else if (day==5) { printf("n Friday"); } else if (day==6) { printf("n Saturday"); } else if (day==7) { printf("n Sunday"); } else { printf("PleaseEnter Correct Value"); } getch(); }
  • 13. 13 11. //Wap to print the name of month. #include<stdio.h> #include<conio.h> void main() { int month; clrscr(); printf("Enter the value for month 1 to 12"); scanf("%d",&month); switch (month) { case 1: printf("January"); break; case 2: printf("Febuary"); break; case 3: printf("March"); break; case 4: printf("April"); break; case 5:
  • 14. 14 printf("May"); break; case 6: printf("June"); break; case 7: printf("July"); break; case 8: printf("August"); break; case 9: printf("September"); break; case 10: printf("October"); break; case 11: printf("November"); break; case 12: printf("December"); break; default:
  • 16. 16 12. //Wap to print 1 to 10 no by while loop #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); while(i<=10) { printf("n %d",i); i++; } getch(); } Output:-
  • 17. 17 13. //Wap to print 1 to 10 Numbers by using do while. #include<stdio.h> #include<conio.h> void main() { int i=1; clrscr(); do { printf("n %d",i); i++; }while(i<=10); getch(); } Output:-
  • 18. 18 14. //Wap to print 1 to 10 by using for loop #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); for(i=1;i<=10;i++) { printf("n %d",i); } getch(); } Output:-
  • 19. 19 15. //Wap to calculate factorial of a given number. #include<stdio.h> #include<conio.h> void main() { int n,i,fact=1; clrscr(); printf("Enter the value of n"); scanf("%d",&n); for(i=n;i>=1;i--) { fact=fact*i; } printf("Factorialis=%d",fact); getch(); } Output:-
  • 20. 20 16. //Wap to print the fibonacci series. #include<stdio.h> #include<conio.h> void main() { int n,i,a=0,b=1,c; clrscr(); printf("Enter the term of fibonacci series"); scanf("%d",&n); printf("%d%d",a,b); for(i=1;i<n;i++) { c=a+b; printf("%d",c); a=b; b=c; } getch(); } Output:-
  • 21. 21 17. //Wap to print the table of given no. #include<stdio.h> #include<conio.h> void main() { int n,i; clrscr(); printf("Enter a Number"); scanf("%d",&n); for(i=1;i<=10;i++) { printf("n %d*%d=%d",n,i,n*i); } getch(); } Output:-
  • 22. 22 18. //Wap to print reverse of a number. #include<stdio.h> #include<conio.h> void main() { int num,n,rev=0,rem; clrscr(); printf("Enter the Number"); scanf("%d",&num); n=num; while(n!=0) { rem=n%10; n=n/10; rev=rev*(10+rem); } printf("Old Number=%d",num); printf("Reversed NO=%d",rev); getch(); } Output:-
  • 23. 23 19. //Wap to print given number is armstrong or not? #include<stdio.h> #include<conio.h> void main() { int num,n,rem,sum=0; clrscr(); printf("Enter a Number"); scanf("%d",&num); n=num; while(n!=0) { rem=n%10; sum=sum+(rem*rem*rem); n=n/10; } if (sum==num) { printf("n Number is Armstrong"); } else { printf("n Number is not Armstrong"); }
  • 25. 25 20. //Wap to print odd numbers between 1 to 50. #include<stdio.h> #include<conio.h> void main() { int i=1; while(i<=50) { if(i%2!=0) printf("n %d",i); i++; } getch(); } Output:-
  • 26. 26 21. //Wap to check given number is palindrome or not? #include<stdio.h> #include<conio.h> void main() { int n,rem,rev=0,num; clrscr(); printf("Enter a Number"); scanf("%d",&n); num=n; while(n!=0) { rem=n%10; n=n/10; rev=((rev*10)+rem); } if(num==rev) { printf("Entered Number is palindrome"); } else { printf("Entered Number is not Palindrome"); }
  • 28. 28 22. //Wap to add two numbers using Functions. #include<stdio.h> #include<conio.h> int sum(int,int); void main() { int a,b,c; printf("enter the values of a and b"); scanf("%d%d",&a,&b); c=sum(a,b); printf("sum=%d",c); getch(); } int sum(intx,int y) { int z; z=x+y; return z; } Output:-
  • 29. 29 23. //Wap to calculate the factorial of given number. #include<stdio.h> #include<conio.h> void main() { int n,result; clrscr(); printf("Enter the value of n"); scanf("%d",&n); result=fact(n); printf("factorial=%d",result); getch(); } int fact(int x) { if (x==0) { return(1); } else { return(x*fact(x-1)); } }
  • 31. 31 24. //Wap to print the fibonacci series. #include<stdio.h> #include<conio.h> int fib(int m); void main() { int n,i; clrscr(); printf("Enter the term of fibonacci series"); scanf("%d",&n); printf("n0"); for(i=1;i<=n;i++) printf("n &d",fib(i)); getch(); } int fib(int m) { static int a=0,b=1; int c; return(0); if(m==1) return(1); else {
  • 33. 33 25. //Wap to calculate simple interest. #include<stdio.h> #include<conio.h> void main() { int p,t,r; int splint; clrscr(); printf("Enter the value of p r and t"); scanf("%d%d%d",&p,&r,&t); splint=(p*r*t/100); printf("Splint=%d",splint); getch(); } Output:-
  • 34. 34 26. //Wap to show concept of function no argument and with return. #include<stdio.h> #include<conio.h> int mul(); void main() { int result; result =mul(); printf("Multiplication=%d",result); getch(); } int mul() { int a,b,c; printf("Enter the value of a and b"); scanf("%d%d",&a,&b); c=a*b; return c; }
  • 35. 35 27. //Wap to show the concept of function with argument and NO return. #include<stdio.h> #include<conio.h> void sub(int,int); void main() { int a,b; clrscr(); printf("Enter the value of a and b"); scanf("%d%d",&a,&b); sub(a,b); getch(); } void sub(intx,int y) { int z; z=x-y; printf("Result=%d",z); } Output:-
  • 36. 36 28.//Wapto show concept of function with no argument no return #include<stdio.h> #include<conio.h> void display(); void programinfo(); void main() { clrscr(); display(); programinfo(); display(); getch(); } void display() { int i; for(i=1;i<=20;i++) printf("*"); printf("n"); } void programinfo() { printf(" No ArgumentNO Return n");
  • 38. 38 29. //Wap to swap two numbers using call by value. #include<stdio.h> #include<conio.h> void swap(int,int); void main() { int a,b; clrscr(); printf("Enter the value of a and b"); scanf("%d%d",&a,&b); swap(a,b); getch(); } void swap(intx,int y) { int z; z=x; x=y; y=z; printf("%d%d",x,y); } Output:-
  • 39. 39 30. //Wap to swap two no by call by reference. #inclu30.de<stdio.h> #include<conio.h> void swap(int*,int *); void main() { int a,b; clrscr(); printf("Enter the value of a and b"); scanf("%d%d",&a,&b); swap(&a,&b); getch(); } void swap(int*x, int *y) { int z; z=*x; *x=*y; *y=z; printf("%d %d",*x,*y); } Output:-
  • 40. 40 31. //Wap to print input elements using One-D array. #include<stdio.h> #include<conio.h> void main() { int a[20],n,i; printf("Enter Array Size"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the value of Elements %d",i); scanf("%d",&a[i]); } printf("Array Elemnets are"); for(i=0;i<n;i++) { printf("n %d",a[i]); getch(); } Output:-
  • 41. 41 32. //Wap to find the maximum value fromarray. #include<stdio.h> #include<conio.h> void main() { int a[50],i,n,max; printf("Enter the array size"); scanf("%d",&n); for(i=0;i<n;i++) { printf("n Enter the values of elements %d",i); scanf("%d",&a[i]); } max=a[50]; for(i=0;i<n;i++) { if(max<a[i]) { max=a[i]; } } printf("Maximumvalue=%d",max); getch() }
  • 43. 43 33. //Wap to find the minimum value fromarray. #include<stdio.h> #include<conio.h> void main() { int a[50],i,n,min; printf("Enter the array size"); scanf("%d",&n); for(i=0;i<n;i++) { printf("n Enter the values of elements %d",i); scanf("%d",&a[i]); } min=a[0]; for(i=0;i<n;i++) { if(min>a[i]) { min=a[i]; } } printf("Minimumvalue=%d",min); getch(); }
  • 45. 45 34. //Wap to print the sum of all array elements. #include<stdio.h> #include<conio.h> void main() { int s[50],i,n,sum=0; clrscr(); printf("Enter the array size"); scanf("%d",&n); for(i=0;i<n;i++) { printf("n Enter sum of student %d",i); scanf("%d",&s[i]); sum=sum+s[i]; } { printf("Sumof Student=%d",sum); } Output:-
  • 46. 46 35. //Wap to print input elements using Two-D array. #include<stdio.h> #include<conio.h> void main() { int a[5][5],j,i,r,c; clrscr(); printf("Enter row and column size"); scanf("%d%d",&r,&c); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("Enter the value of Elements %d%d:",i,j); scanf("%d",&a[i][j]); } } printf("Array Elemnets are"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("n %d",a[i][j]); }
  • 48. 48 36. //Wap to add two matrices. #include<stdio.h> #include<conio.h> void main() { int a[5][5],b[5][5],c[5][5]; int i,j,r,col; clrscr(); printf("Enter the row and column size"); scanf("%d%d",&r,&col); printf("n Enter the values of firstmatrix"); for(i=0;i<r;i++) { for(j=0;j<col;j++) { printf("n Enter the values of elements %d%d",i,j); scanf("%d",&a[i][j]); } } printf("n Enter the values of second matrix"); for(i=0;i<r;i++) { for(j=0;j<col;j++)
  • 49. 49 { printf("n Enter the values of elements %d%d",i,j); scanf("%d",&b[i][j]); } } for(i=0;i<r;i++) { for(j=0;j<col;j++) { c[i][j]=0; c[i][j]=a[i][j]+b[i][j]; } } printf("n After Addition n"); for(i=0;i<r;i++) { for(j=0;j<col;j++) { printf("%dt",c[i][j]); } printf("n"); } getch(); }
  • 51. 51 37. //Wap to multiply two matrices. #include<stdio.h> #include<conio.h> void main() { int a[5][5],b[5][5],c[5][5]; int i,j,r,col; clrscr(); printf("Enter the row and column size"); scanf("%d%d",&r,&col); printf("n Enter the values of firstmatrix"); for(i=0;i<r;i++) { for(j=0;j<col;j++) { printf("n Enter the values of elements %d%d",i,j); scanf("%d",&a[i][j]); } } printf("n Enter the values of second matrix"); for(i=0;i<r;i++) { for(j=0;j<col;j++) {
  • 52. 52 printf("n Enter the values of elements %d%d",i,j); scanf("%d",&b[i][j]); } } for(i=0;i<r;i++) { for(j=0;j<col;j++) { c[i][j]=0; c[i][j]=a[i][j]*b[i][j]; } } printf("n After Multiplication n"); for(i=0;i<r;i++) { for(j=0;j<col;j++) { printf("%dt",c[i][j]); } printf("nn"); } getch(); }
  • 54. 54 38. //Wap to subtract two matrices. #include<stdio.h> #include<conio.h> void main() { int a[5][5],b[5][5],c[5][5]; int i,j,r,col; clrscr(); printf("Enter the row and column size"); scanf("%d%d",&r,&col); printf("n Enter the values of firstmatrix"); for(i=0;i<r;i++) { for(j=0;j<col;j++) { printf("n Enter the values of elements %d%d",i,j); scanf("%d",&a[i][j]); } } printf("n Enter the values of second matrix"); for(i=0;i<r;i++) { for(j=0;j<col;j++) {
  • 55. 55 printf("n Enter the values of elements %d%d",i,j); scanf("%d",&b[i][j]); } } for(i=0;i<r;i++) { for(j=0;j<col;j++) { c[i][j]=0; c[i][j]=a[i][j]-b[i][j]; } } printf("n After Subtraction n"); for(i=0;i<r;i++) { for(j=0;j<col;j++) { printf("%dt",c[i][j]); } printf("n"); } getch(); }
  • 57. 57 39. //Wap to Transpose a matrix. #include<stdio.h> #include<conio.h> void main() { int a[5][5],i,j,r,c; clrscr(); printf("Enter the row and column size"); scanf("%d%d",&r,&c); printf("n Enter the values of firstmatrix"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("n Enter the values of elements %d%d",i,j); scanf("%d",&a[i][j]); } } printf("n After Transposen"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("%dt",a[i][j]);
  • 59. 59 40. //Wap to print diagonal elements of a matrix. #include<stdio.h> #include<conio.h> void main() { int a[5][5],i,j,r,c; clrscr(); printf("Enter the row and column size"); scanf("%d%d",&r,&c); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("n Enter the values of elements %d%d",i,j); scanf("%d",&a[i][j]); } } printf("n Diagonal Elements are n"); for(i=0;i<j;i++) { for(j=0;j<c;j++) { if(i==j) {
  • 61. 61 41. //Wap to print sum of diagonal elements of a matrix. #include<stdio.h> #include<conio.h> void main() { int a[5][5],i,j,r,c,sum=0; clrscr(); printf("Enter the row and column size"); scanf("%d%d",&r,&c); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("n Enter the values of elements %d%d",i,j); scanf("%d",&a[i][j]); } } for(i=0;i<r;i++) { for(j=0;j<c;j++) { if(i==j) {
  • 62. 62 sum+=a[i][j]; } } printf("n Sum of DiagonalElements are=%d",sum); getch(); }
  • 63. 63 42. //Wap to calculate % in four subjects And show rollno of students. #include<stdio.h> #include<conio.h> structstudent { int rollno; float sub1,sub2,sub3,sub4,per; }; void main() { struct students1; clrscr(); printf("Enter the info for students"); printf("n Enter the roll no for student:"); scanf("%d",&s1.rollno); printf("Enter the marks for sub1,sub2,sub3,sub4"); scanf("%f%f%f%f",&s1.sub1,&s1.sub2,&s1.sub3,&s1.sub4); s1.per=(s1.sub1+s1.sub2+s1.sub3+s1.sub4)/400*100; printf("Info for student"); printf("n Roll no of Student=%d",s1.rollno); printf("n Percentage of student=%f",s1.per); getch();
  • 65. 65 43. //Wap to print record of a school student. #include<stdio.h> #include<conio.h> structstudent { int rollno; int age; char name; float marks,sub1,sub2,per; }; void main() { struct students1; clrscr(); printf("Enter the info for students"); printf("n Enter the Name of student:"); scanf("%s",&s1.name); printf("n Enter the roll no for student:"); scanf("%d",&s1.rollno); printf("Enter the Age of student:"); scanf("%d",&s1.age); printf("Enter the marks for sub1,sub2"); scanf("%f%f",&s1.sub1,&s1.sub2);
  • 66. 66 s1.per=(s1.sub1+s1.sub2)/200*100; printf("Info for student"); printf("n Name of student %s",s1.name); printf("n Roll no of Student=%d",s1.rollno); printf("n Age of student:%d",s1.age); printf("n Marks of sub1 and sub2 of student:%f %f",s1.sub1,s1.sub2); printf("n Percentage of student=%f",s1.per); getch(); } Output:-
  • 67. 67 44. //Wap to print record of students using union. #include<stdio.h> #include<conio.h> union student { int rollno; char name[20]; int age; float marks; } s; void main() { printf("Enter RollNo of Student :"); scanf("%d",&s.rollno); printf("Enter the age of student :"); scanf("%d",&s.age); printf("Enter the name of student:"); scanf("%s",&s.name); printf("Enter the marks of student :"); scanf("%f",&s.marks); printf("n RollNo=%d",s.rollno); printf("n age=%d",s.age); printf("n Name=%s",s.name); printf("n marks=%f",s.marks); getch(); }
  • 68. 68 45. //Wap to print address & value of variable and address of pointer variable. #include<stdio.h> #include<conio.h> void main() { int * ptr; int a=10; clrscr(); ptr=&a; printf("n %d",a); scanf("%ld",&ptr); printf("%ld",*ptr); printf("n %ld",*ptr); printf("n %ld",&a); getch(); } Output:-
  • 69. 69 46. //Wap to show the concept of pointer to pointer. #include<stdio.h> #include<conio.h> void main() { int ** ptr; int * p; int a=10; clrscr(); p=&a; ptr=&p; printf("n Value of a=%d",a); printf("n Address of p=%ld",&p); printf("n Value of p=%ld",p); printf("n Content of a through p=%d",*p); printf("n Address of p through ptr=%ld",ptr); printf("n Content of a through ptr=%d",**ptr); getch(); }
  • 70. 70 47. //Wap to show use of auto variable. #include<stdio.h> #include<conio.h> void func1(); void main() { func1(); func1(); } void func1() { auto int i=2; printf("%dn",i); i=i+2; getch(); } Output:-
  • 71. 71 48. //Wap to show use of static variable. #include<stdio.h> #include<conio.h> int func1(); int func2(); main() { static int i=1; printf("%d",i); printf("n%d",func1()); printf("n%d",func2()); } int func1() { static int i; i=i+2; return(i); } int func2() { static int i; i=i+3; return(i); getch(); } Output:-
  • 72. 72 49. //Wap to show use of external variable. #include<stdio.h> #include<conio.h> int i=1; int func1(); int func2(); void main() { printf("%d",i); printf("n%d",func1()); printf("n%d",func2()); } int func1() { i=i+10; return(i); } int func2() { i=i+20; return(i); getch(); }
  • 74. 74 50. //Wap to enter a mixed data into a file. #include<stdio.h> #include<conio.h> void main() { FILE*fp; int rollno; char name[20]; float marks; fp=fopen("stud.txt","w"); clrscr(); if(fp==NULL) { printf("Cannotopen file"); } printf("Enter student name,rollno,marks"); scanf("%s %d %f",name,&rollno,&marks); fprintf(fp,"%s %d %f",name,rollno,marks); fclose(fp); getch(); }
  • 76. 76 51. //Wap to read a mixed data froma file. #include<stdio.h> #include<conio.h> void main() { FILE*fp; int rollno; char name[20]; float marks; fp=fopen("stud.txt","r"); clrscr(); if(fp==NULL) { printf("Cannotopen file"); } while(fscanf(fp,"%s %d %f",name,&rollno,&marks)!=EOF) { printf("%s %d %f",name,rollno,marks); } fclose(fp); getch(); } Output
  • 77. 77 52. //Wap to enter a string data into a file. #include<stdio.h> #include<conio.h> void main() { FILE*fp; char s[80]; fp=fopen("xyz.txt","w"); if(fp==NULL) { printf("Cannotopen file"); } printf("Enter string data and press enter"); while((strlen(gets(s))>0)) { fputs(s,fp); fputs("n",fp); } close(fp); }
  • 79. 79 53. //Wap to read a string data from a file. #include<stdio.h> #include<conio.h> void main() { FILE*fp; char s[80]; clrscr(); fp=fopen("xyz.txt","r"); if(fp==NULL) { printf("Cannotopen file"); } while(fgets(s,80,fp)!=NULL) puts(s); fclose(fp); getch(); } Output:-
  • 80. 80 54. //Wap to write integer into a file. #include<stdio.h> #include<conio.h> void main() { FILE*fp; int n; fp=fopen("raj.txt","w"); clrscr(); if(fp==NULL) { printf("Cannotopen file"); } printf("Enter any integar value"); scanf("%d",&n); putw(n,fp); fclose(fp); getch(); }
  • 82. 82 55. //Wap to read integer into a file. #include<stdio.h> #include<conio.h> void main() { FILE*fp; int n; fp=fopen("raj.txt","w"); clrscr(); if(fp==NULL) { printf("Cannotopen file"); } while((n=getw(fp))!=EOF) { printf("%d",n); } fclose(fp); getch(); } Output:-