Lab programs of C
- Important programs of c language
Note:
1.some program and out puts are not their in blog those will be posted soon.
2.some program not run in phone and some are show different out puts in phone .So, those type programs try in system..
🙏Please do follow, share and subscribe ,any mistake in blog comment 🙏
1.Program on Escape squence.
#include<stdio.h>
int main()
{
int a=5;
printf("%d\n",a);
printf("a value=%d\t",a);
return 0;
}
2.Swaping of two numbers.
i】Swaping of two numbers with out use of third variable.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
printf("enter a, b values\n");
scanf("%d%d",&a,&b);
printf("before swape\n a=%d\n b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("after swape\n a=%d\n b=%d",a,b);
getch();
}
ii】Swaping of two numbers with use of third variable.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,t;
clrscr();
printf("enter a, b values\n");
scanf("%d%d",&a,&b);
printf("before swape\n a=%d\n b=%d\n",a,b);
t=a;
a=b;
b=t;
printf("after swape\n a=%d\n b=%d",a,b);
getch();
}
i】Swaping of two numbers with out use of third variable.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
printf("enter a, b values\n");
scanf("%d%d",&a,&b);
printf("before swape\n a=%d\n b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("after swape\n a=%d\n b=%d",a,b);
getch();
}
ii】Swaping of two numbers with use of third variable.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,t;
clrscr();
printf("enter a, b values\n");
scanf("%d%d",&a,&b);
printf("before swape\n a=%d\n b=%d\n",a,b);
t=a;
a=b;
b=t;
printf("after swape\n a=%d\n b=%d",a,b);
getch();
}
3.write a program to c=(f-32)*5/9.
#include<stdio.h>
#include<conio.h>
int main()
{
float c,f;
printf("Enter f value\n");
scanf("%f\n",&f);
c=(f-32)*5/9;
printf("c=%f",c);
getch();
}
4.write a program on si=(p*n*r)/100.
#include<stdio.h>
#include<conio.h>
main()
{
int p,n,r,si;
clrscr();
printf("Enter Principle, Rate of interest & Time :");
scanf("%d%d%d",&p,&r,&n);
si=(p*r*n)/100;
printf("Simple Interest is :%d",si);
getch();
}
#include<stdio.h>
#include<conio.h>
#include <math.h>
int main()
{
int n;
clrscr();
n=4;
printf("%f\n%f\n%f\n",sqrt(n),exp(n),log(n));
n=90;
printf("%f\n%f\n%f\n",sin(n),cos(n),tan(n));
n=-10;
printf("%f\n",fabs(n));
getch();
}
6.Write a program on Area of a triangle.
#include<stdio.h>
#include<conio.h>
#include <math.h>
int main()
{
int a,b,c;
float s,n;
clrscr();
printf("Enter three sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
s=(float)(a+b+c)/2;
n=sqrt(s*(s-a)*(s-b)*(s-c));
printf("area=%f\n",n);
getch();
}
7.Write a program on Squre and cub of number.
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
printf("squar :%d\ncube :%d",(n*n),(n*n*n));
getch();
}
8.Write a program on Area and Circumference of Circle.
#include<stdio.h>
#include<conio.h>
int main()
{
float r;
clrscr();
printf("Enter radius\n");
scanf("%f",&r);
printf("area=%f\ncircumference=%f",(3.14*r*r),(2*3.14*r));
getch();
}
#include<conio.h>
int main()
{
float r;
clrscr();
printf("Enter radius\n");
scanf("%f",&r);
printf("area=%f\ncircumference=%f",(3.14*r*r),(2*3.14*r));
getch();
}
9.Write a program on Area of a triangle
#include<stdio.h>
#include<conio.h>
#include <math.h>
int main()
{
int a,b,c;
float s,n;
clrscr();
printf("Enter three sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
s=(float)(a+b+c)/2;
n=sqrt(s*(s-a)*(s-b)*(s-c));
printf("area=%f\n",n);
getch();
}
10.writea program on implicit data convertion
i】Converting ininto float
#include<stdio.h>
int main()
{
int a;
float x=2.5;
a=x;
printf("a=%d\n",a);
return 0;
}
ii】Converting float into int
#include<stdio.h>
#include<conio.h>
int main()
{
int a=9;
float x;
clrscr();
x=a;
printf("x=%f\n",x);
getch();
}
iii】Converting int into ASCII
#include<stdio.h>
#include<conio.h>
int main()
{
int a; char c;
clrscr();
printf("Enter a char\n");
scanf("%c",&c);
a=c;
printf("ASCII int is=%d\n",a);
getch();
}
iv】Char to ASCII int
#include<stdio.h>
#include<conio.h>
int main()
{
int a; char c;
clrscr();
printf("Enter a value\n");
scanf("%d",&a);
c=a;
printf("ASCII int is=%c\n",c);
getch();
}
11.Explicit data conversion -division of two integers.
#include<stdio.h>
#include<conio.h>
int main()
{
int a=9,b=5,c;
clrscr();
printf("division=%f\n",float(a/b));
getch();
}
12.write a program on operator of C-language
i】Arithemetic operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
clrscr();
printf("add=%d\nsub=%d\n",(a+b),(a-b)); printf("mul=%d\ndiv=%f\n",(a+b),(float)a/b);
printf("rem=%d\n",(a%b));
getch();
}
ii】Relational operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
clrscr();
printf("%d\n%d\n",(a>b),(a<=b));
printf("%d\n%d\n",(a==b),(a!=b));
getch();
}
iii】Logical opperators
#include<stdio.h>
#include<conio.h>
int main()
{
int a=15,b=10,c=5;
clrscr();
printf("%d\n",(a>b)&&(a>c));
printf("%d\n",(a>b)||(a>c));
getch();
}
iv】Assigment Operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
clrscr();
b=a;
a=b; b=a;
printf("a=%d\nb=%d",a,b);
getch();
}
v】Ternary aoperator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10,c;
clrscr();
c=(a>b)?a:b;
printf("max=%d\n",c);
getch();
}
vi】Bitwise operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=7;
clrscr();
printf("%d\n%d\n",(a>>b),(a<<b));
printf("%d\n%d\n",(a&b),(a|b));
printf("%d\n%d\n",(~a),(a^b));
getch();
}
i】Converting ininto float
#include<stdio.h>
int main()
{
int a;
float x=2.5;
a=x;
printf("a=%d\n",a);
return 0;
}
ii】Converting float into int
#include<stdio.h>
#include<conio.h>
int main()
{
int a=9;
float x;
clrscr();
x=a;
printf("x=%f\n",x);
getch();
}
iii】Converting int into ASCII
#include<stdio.h>
#include<conio.h>
int main()
{
int a; char c;
clrscr();
printf("Enter a char\n");
scanf("%c",&c);
a=c;
printf("ASCII int is=%d\n",a);
getch();
}
iv】Char to ASCII int
#include<stdio.h>
#include<conio.h>
int main()
{
int a; char c;
clrscr();
printf("Enter a value\n");
scanf("%d",&a);
c=a;
printf("ASCII int is=%c\n",c);
getch();
}
11.Explicit data conversion -division of two integers.
#include<stdio.h>
#include<conio.h>
int main()
{
int a=9,b=5,c;
clrscr();
printf("division=%f\n",float(a/b));
getch();
}
12.write a program on operator of C-language
i】Arithemetic operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
clrscr();
printf("add=%d\nsub=%d\n",(a+b),(a-b)); printf("mul=%d\ndiv=%f\n",(a+b),(float)a/b);
printf("rem=%d\n",(a%b));
getch();
}
ii】Relational operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
clrscr();
printf("%d\n%d\n",(a>b),(a<=b));
printf("%d\n%d\n",(a==b),(a!=b));
getch();
}
iii】Logical opperators
#include<stdio.h>
#include<conio.h>
int main()
{
int a=15,b=10,c=5;
clrscr();
printf("%d\n",(a>b)&&(a>c));
printf("%d\n",(a>b)||(a>c));
getch();
}
iv】Assigment Operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
clrscr();
b=a;
a=b; b=a;
printf("a=%d\nb=%d",a,b);
getch();
}
v】Ternary aoperator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10,c;
clrscr();
c=(a>b)?a:b;
printf("max=%d\n",c);
getch();
}
vi】Bitwise operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=7;
clrscr();
printf("%d\n%d\n",(a>>b),(a<<b));
printf("%d\n%d\n",(a&b),(a|b));
printf("%d\n%d\n",(~a),(a^b));
getch();
}
13.write a program on maximum of two numbers
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
clrscr();
if(a>b)
printf("a is max\n");
else
printf("b is max");
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
clrscr();
if(a>b)
printf("a is max\n");
else
printf("b is max");
getch();
}
14. Write a program if radios is even determine area else circumference
#include<stdio.h>
#include<conio.h>
int main()
{
int r;
clrscr();
printf("Enter radius\n");
scanf("%d",&r);
if(r%2==0)
printf("area=%f\n",(3.14*r*r));
else
printf("circumference=%f",(2*3.14*r));
getch();
}
#include<conio.h>
int main()
{
int r;
clrscr();
printf("Enter radius\n");
scanf("%d",&r);
if(r%2==0)
printf("area=%f\n",(3.14*r*r));
else
printf("circumference=%f",(2*3.14*r));
getch();
}
15.write a program to find a number is positive or negative
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
if(n>0)
printf("n is positive");
else
printf("n is negative");
getch();
}
16.Write a program to accepting student marked finding distinct,first,second,third,fail
#include<stdio.h>
#include<conio.h>
int main()
{
int m;
clrscr();
printf("Enter markes\n");
scanf("%d",&m);
if(m>100)
printf("Invalid");
else if(m>74)
printf("distinction");
else if(m>59)
printf("first");
else if(m>49)
printf("second");
else if(m>34)
printf("third");
else
printf("fail");
getch();
}
17. Write a program determine the triangle is valid or not
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("Enter three sides of a triangle\n");
scanf("%d%d%d",&a,&b,&c);
if((a+b)>c&&(a+c)>b&&(b+c)>a)
printf("valid triangle");
else
printf("not valid triangle ");
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
if(n>0)
printf("n is positive");
else
printf("n is negative");
getch();
}
16.Write a program to accepting student marked finding distinct,first,second,third,fail
#include<stdio.h>
#include<conio.h>
int main()
{
int m;
clrscr();
printf("Enter markes\n");
scanf("%d",&m);
if(m>100)
printf("Invalid");
else if(m>74)
printf("distinction");
else if(m>59)
printf("first");
else if(m>49)
printf("second");
else if(m>34)
printf("third");
else
printf("fail");
getch();
}
17. Write a program determine the triangle is valid or not
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("Enter three sides of a triangle\n");
scanf("%d%d%d",&a,&b,&c);
if((a+b)>c&&(a+c)>b&&(b+c)>a)
printf("valid triangle");
else
printf("not valid triangle ");
getch();
}
18.Find any arithmetic operation using if else if ladder
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("Enter a,b values\n");
scanf("%d%d",&a,&b);
printf("Arthimatic operatim\n");
printf("1.Add\n2.sub\n3.mult\n4.div\n5.rem\n");
printf("Enter choice\n");
scanf("%d",&c);
if(c==1)
printf("add=%d\n",(a+b));
else if(c==2)
printf("sub=%d\n",(a-b));
else if(c==3)
printf("mul=%d\n",(a*b));
else if(c==4)
printf("div=%f\n",(float)a/b);
else if(c==5)
printf("rem=%d\n",(a%b));
else printf("invalide");
getch();
}
19.W.A.P determine leap year or not using logical operator
#include<stdio.h>
#include<conio.h>
int main()
{
int y;
clrscr();
printf("Enter year\n");
scanf("%d",&y);
if(y>1400)
{
if(y%4==0)
{
if((y%100!=0)||(y%400==0))
printf("it is a leap year");
}
else
printf("it is not leap year");
}
getch();
}
20.Max of 3 No's using logical operator
#include<stdio.h>
#include<conio.h>
int main()
{
int m1,m2,m3;
clrscr();
printf("Enter m1,m2 and m3\n");
scanf("%d%d%d",&m1,&m2,&m3);
if((m1>34)&&(m2>34)&&(m3>34))
printf("pass");
else
printf("fail");
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("Enter a,b values\n");
scanf("%d%d",&a,&b);
printf("Arthimatic operatim\n");
printf("1.Add\n2.sub\n3.mult\n4.div\n5.rem\n");
printf("Enter choice\n");
scanf("%d",&c);
if(c==1)
printf("add=%d\n",(a+b));
else if(c==2)
printf("sub=%d\n",(a-b));
else if(c==3)
printf("mul=%d\n",(a*b));
else if(c==4)
printf("div=%f\n",(float)a/b);
else if(c==5)
printf("rem=%d\n",(a%b));
else printf("invalide");
getch();
}
19.W.A.P determine leap year or not using logical operator
#include<stdio.h>
#include<conio.h>
int main()
{
int y;
clrscr();
printf("Enter year\n");
scanf("%d",&y);
if(y>1400)
{
if(y%4==0)
{
if((y%100!=0)||(y%400==0))
printf("it is a leap year");
}
else
printf("it is not leap year");
}
getch();
}
20.Max of 3 No's using logical operator
#include<stdio.h>
#include<conio.h>
int main()
{
int m1,m2,m3;
clrscr();
printf("Enter m1,m2 and m3\n");
scanf("%d%d%d",&m1,&m2,&m3);
if((m1>34)&&(m2>34)&&(m3>34))
printf("pass");
else
printf("fail");
getch();
}
21.Accept 3 subs marks, if every subject marks >=35 then student is pass else fail , reasons for failure
#include<stdio.h>
#include<conio.h>
int main()
{
int m1,m2,m3;
clrscr();
printf("Enter m1,m2 and m3\n");
scanf("%d%d%d",&m1,&m2,&m3);
if(m1>=35)
{
if(m2>=35)
{
if(m3>=35)
printf("pass");
else
printf("fail in m3");
}
else
printf("fail in m2");
}
else
printf("fail in m1");
}
getch();
}
22. Max of 3 no's without using logical operator
#include<stdio.h>
#include<conio.h>
int main()
{
int m1,m2,m3;
clrscr();
printf("Enter m1,m2 and m3\n");
scanf("%d%d%d",&m1,&m2,&m3);
if(m1>=35)
{
if(m2>=35)
{
if(m3>=35)
printf("pass");
else
printf("fail in m3");
}
else
printf("fail in m2");
}
else
printf("fail in m1");
}
getch();
}
22. Max of 3 no's without using logical operator
#include<stdio.h>
#include<conio.h>
int main()
{
int a=7,b=24,c=15;
clrscr();
if(a>b)
{
if(a>c)
printf("a is max\n");
else printf("c is max");
}
if(b>c)
printf(" b is max");
else
printf("c is max");
getch();
}
23.W.A.P selection process for S.I post
//Well be posted soon
#include<conio.h>
int main()
{
int a=7,b=24,c=15;
clrscr();
if(a>b)
{
if(a>c)
printf("a is max\n");
else printf("c is max");
}
if(b>c)
printf(" b is max");
else
printf("c is max");
getch();
}
23.W.A.P selection process for S.I post
//Well be posted soon
24.W.A.P selection process for IAS,IPS and IRS
#include<stdio.h>
#include<conio.h>
void main()
{
int pri,p1,p2,viva;
clrscr();
printf("enter pri exam marks(min-50)\n");
scanf("%d",&pri);
if(pri>=50&&pri<=100)
{
printf("enter main exams p1,p2,p1-60,p2-70\n");
scanf("%d%d",&p1,&p2);
if(p1>=60&&p1<=100&&p2>=70&&p2<=100){
printf("enter vi a marks viva-80\n");
scanf("%d",&viva);
if(viva>=80&&viva<=100)
{
if(pri+p1+p2+viva<=300)
printf("selected for irs");
else if
(pri+p1+p2+viva<=350)
printf("selected for ips");
else
printf("selected for ias");
}
else
printf("not selected due to viva");
}
else
printf("not selected due to main exams");
}
else("not selected due to pri-exams");
getch();
}
25.WAP on switch statement ...
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
char ch;
clrscr();
printf("Enter a,b values\n");
scanf("%d%d",&a,&b);
printf("Arthimatic operatim\n");
printf("1.Add\n2.sub\n3.mult\n4.div\n5.rem\n");
printf("Enter choice\n");
scanf("%c",&ch);
ch=getchar();
switch(ch)
{
case'1':printf("add=%d\n",(a+b));
break;
case'2':printf("sub=%d\n",(a-b));
break;
case'3':printf("mul=%d\n",(a*b));
break;
case'4':printf("div=%f\n",(float)a/b); break;
case'5':printf("rem=%d\n",(a%b));
break;
}
getch();
}
26.Determine any one arithmetic operations using switch statement
#include<stdio.h>
#include<conio.h>
int main()
{
char ch1,ch2;
clrscr();
printf("enter your choice pg/ug\n");
ch1=getchar();
switch(ch1)
{
case'p':printf("pg class at 10am\n");
break;
case'u':printf("enter your choice in ug(s/a)\n");
fflush(stdin);
ch2=getchar();
switch(ch2){
case's':printf("ug science at 8am\n");
break;
case'a':printf("ug art at 12:30pm\n");
break;
default:printf("invaled choice\n");
}
break;
default:printf("invaped choice");
}
}
27.WAP on quadratic equation with effect of goto
#include<stdio.h>
#include<conio.h>
void main()
{
int pri,p1,p2,viva;
clrscr();
printf("enter pri exam marks(min-50)\n");
scanf("%d",&pri);
if(pri>=50&&pri<=100)
{
printf("enter main exams p1,p2,p1-60,p2-70\n");
scanf("%d%d",&p1,&p2);
if(p1>=60&&p1<=100&&p2>=70&&p2<=100){
printf("enter vi a marks viva-80\n");
scanf("%d",&viva);
if(viva>=80&&viva<=100)
{
if(pri+p1+p2+viva<=300)
printf("selected for irs");
else if
(pri+p1+p2+viva<=350)
printf("selected for ips");
else
printf("selected for ias");
}
else
printf("not selected due to viva");
}
else
printf("not selected due to main exams");
}
else("not selected due to pri-exams");
getch();
}
25.WAP on switch statement ...
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
char ch;
clrscr();
printf("Enter a,b values\n");
scanf("%d%d",&a,&b);
printf("Arthimatic operatim\n");
printf("1.Add\n2.sub\n3.mult\n4.div\n5.rem\n");
printf("Enter choice\n");
scanf("%c",&ch);
ch=getchar();
switch(ch)
{
case'1':printf("add=%d\n",(a+b));
break;
case'2':printf("sub=%d\n",(a-b));
break;
case'3':printf("mul=%d\n",(a*b));
break;
case'4':printf("div=%f\n",(float)a/b); break;
case'5':printf("rem=%d\n",(a%b));
break;
}
getch();
}
26.Determine any one arithmetic operations using switch statement
#include<stdio.h>
#include<conio.h>
int main()
{
char ch1,ch2;
clrscr();
printf("enter your choice pg/ug\n");
ch1=getchar();
switch(ch1)
{
case'p':printf("pg class at 10am\n");
break;
case'u':printf("enter your choice in ug(s/a)\n");
fflush(stdin);
ch2=getchar();
switch(ch2){
case's':printf("ug science at 8am\n");
break;
case'a':printf("ug art at 12:30pm\n");
break;
default:printf("invaled choice\n");
}
break;
default:printf("invaped choice");
}
}
27.WAP on quadratic equation with effect of goto
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c,d,r1,r2;
clrscr();
back:printf("enter a,bc values\n");
scanf("%f%f%f",&a,&b,&c);
if(a==0)
{
printf("roots are infinite\nRe-");
goto back;
}
d=(b*b)-(4*a*c);
if(d==0)
{
r1=-b/(2*a);
r2=r1;
printf("roots are equal\n");
printf("r1=%f\nr2=%f\n",r1,r2);
}
else if(d>0){
printf("roots are distinct\n");
r1=(-b+sqrt(d)/(2*a));
r2=(-b-sqrt(d)/(2*a));
printf("r1=%f\nr2=%f\n",r1,r2);}
else{
printf("root are imaginary\n");
goto back;
}
getch();
}
28. Program on gotoxy
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
clrscr();
printf("enter your number\n");
scanf("%d",&a);
gotoxy(5,5);
printf("%d",a);
getch();
}
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c,d,r1,r2;
clrscr();
back:printf("enter a,bc values\n");
scanf("%f%f%f",&a,&b,&c);
if(a==0)
{
printf("roots are infinite\nRe-");
goto back;
}
d=(b*b)-(4*a*c);
if(d==0)
{
r1=-b/(2*a);
r2=r1;
printf("roots are equal\n");
printf("r1=%f\nr2=%f\n",r1,r2);
}
else if(d>0){
printf("roots are distinct\n");
r1=(-b+sqrt(d)/(2*a));
r2=(-b-sqrt(d)/(2*a));
printf("r1=%f\nr2=%f\n",r1,r2);}
else{
printf("root are imaginary\n");
goto back;
}
getch();
}
28. Program on gotoxy
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
clrscr();
printf("enter your number\n");
scanf("%d",&a);
gotoxy(5,5);
printf("%d",a);
getch();
}
29. Program on sum of digits
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
sum=0;
while(n>0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("sum=%d\n",sum);
getch();
}
30.Program on reverse of number
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
sum=0;
while(n>0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("sum=%d\n",sum);
getch();
}
30.Program on reverse of number
#include<stdio.h>
#include<conio.h>
int main()
{
int n,rev,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
rev=0;
while(n>0)
{
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
}
printf("rev=%d\n",rev);
getch();
}
31.Program to find the given no is amstrong num are not
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,sum,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
sum=0;
i=n;
while(n>0)
{
rem=n%10;
sum=sum+(rem*rem*rem);
n=n/10;
}
if(i==sum)
printf("it is an amstrong no");
else
printf("it is not amstrong no");
getch();
}
#include<conio.h>
int main()
{
int n,rev,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
rev=0;
while(n>0)
{
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
}
printf("rev=%d\n",rev);
getch();
}
31.Program to find the given no is amstrong num are not
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,sum,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
sum=0;
i=n;
while(n>0)
{
rem=n%10;
sum=sum+(rem*rem*rem);
n=n/10;
}
if(i==sum)
printf("it is an amstrong no");
else
printf("it is not amstrong no");
getch();
}
32.program to find the given num is palindrome or not
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,rev,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
i=n;
rev=0;
while(n>0)
{
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
}
if(i==rev)
printf("it is a palindrom num");
else
printf("it is not a palindrom num");
getch();
}
33.program to find the factorial of given num
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,s=0;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(n%i==0)
printf("\n%d",i);
}
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,rev,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
i=n;
rev=0;
while(n>0)
{
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
}
if(i==rev)
printf("it is a palindrom num");
else
printf("it is not a palindrom num");
getch();
}
33.program to find the factorial of given num
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,s=0;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(n%i==0)
printf("\n%d",i);
}
getch();
}
34.program sum and avg of all even and odd no's
#include<stdio.h>
#include<conio.h>
int main()
{
int i=0,n,c=0,even=0,odd=0,seven=0,sodd=0;
float eavg,oavg;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0){
seven=seven+i;
c++;
}
else
sodd=sodd+i;
}
eavg=seven/c;
oavg=sodd/(n-c);
printf("sum of even=%d\n eavg=%f\n",seven,eavg);
printf("sum of odd=%d\n oavg=%f",sodd,oavg);
getch();
}
#include<conio.h>
int main()
{
int i=0,n,c=0,even=0,odd=0,seven=0,sodd=0;
float eavg,oavg;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0){
seven=seven+i;
c++;
}
else
sodd=sodd+i;
}
eavg=seven/c;
oavg=sodd/(n-c);
printf("sum of even=%d\n eavg=%f\n",seven,eavg);
printf("sum of odd=%d\n oavg=%f",sodd,oavg);
getch();
}
35.program to find sum and avg from 1 to N no's
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,sum=0,avg;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
avg=(float)sum/n;
printf("sum=%d\n avg=%f",sum,avg);
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,sum=0,avg;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
avg=(float)sum/n;
printf("sum=%d\n avg=%f",sum,avg);
getch();
}
36.WAP to find the sum of digits using interative itaration
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum=0,rem;
char ch;
do{
printf("Enter a number\n");
scanf("%d",&n);
while(n>0){
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("sum of digits=%d\n",sum);
printf("Do you want to continue(y/n)");
fflush(stdin);
ch=getchar();
}
while(ch=='y');
getch();
}
37.program to find sum of the factors of given no's
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum=0,i;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++){
if(n%i==0)
{
printf("\n%d",i);
sum=sum+i;
}}
printf("\nsum of factors=%d",sum);
getch();
}
38.program to find given no is perfect are not
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum=0,i;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++){
if(n%i==0)
sum=sum+i;
}
if(sum==n*2)
printf("enter value is perfect number");
else
printf("Enter value is not perfect no");
getch();
}
39.WAP prime number is prime or not
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,c=0;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
printf("it is a prime number");
else
printf("it is not a prime number");
getch();
}
40.program on Fibanacci series of a no
#include<stdio.h>
#include<conio.h>
int main()
{
int a=0,b=1,c,n,i;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
c=a+b;
printf("%d\t",c);
a=b;
b=c;
}
getch();
}
41.WAP on multiplication table of a given number
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,mul;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
mul=i*n;
printf("%d*%d=%d\n",i,n,mul);
}
getch();
}
42.WAP on convert ASCIIkey character(capital) into integer
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n;
char ch='A';
clrscr();
for(i=1;i<=26;i++)
{
n=ch;
printf("\nchar %cASCII integer value %d\n",ch,n);
ch++;
}
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum=0,rem;
char ch;
do{
printf("Enter a number\n");
scanf("%d",&n);
while(n>0){
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("sum of digits=%d\n",sum);
printf("Do you want to continue(y/n)");
fflush(stdin);
ch=getchar();
}
while(ch=='y');
getch();
}
37.program to find sum of the factors of given no's
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum=0,i;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++){
if(n%i==0)
{
printf("\n%d",i);
sum=sum+i;
}}
printf("\nsum of factors=%d",sum);
getch();
}
38.program to find given no is perfect are not
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum=0,i;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++){
if(n%i==0)
sum=sum+i;
}
if(sum==n*2)
printf("enter value is perfect number");
else
printf("Enter value is not perfect no");
getch();
}
39.WAP prime number is prime or not
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,c=0;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
printf("it is a prime number");
else
printf("it is not a prime number");
getch();
}
40.program on Fibanacci series of a no
#include<stdio.h>
#include<conio.h>
int main()
{
int a=0,b=1,c,n,i;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
c=a+b;
printf("%d\t",c);
a=b;
b=c;
}
getch();
}
41.WAP on multiplication table of a given number
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,mul;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
mul=i*n;
printf("%d*%d=%d\n",i,n,mul);
}
getch();
}
42.WAP on convert ASCIIkey character(capital) into integer
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n;
char ch='A';
clrscr();
for(i=1;i<=26;i++)
{
n=ch;
printf("\nchar %cASCII integer value %d\n",ch,n);
ch++;
}
getch();
}
43.WAP to find Effect of break and continue in a loop
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
clrscr();
printf("effect of break\n");
for(i=1;i<=5;i++)
{
if(i==2)
break;
printf("%d\n",i);
}
printf("effect of continue\n");
for(i=1;i<=5;i++)
{
if(i==2)
continue;
printf("%d\n",i);
}
getch();
}
44.WAP on multiplication table of a given number
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,mul,j;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=10;j++)
{
mul=i*j;
printf("%d*%d=%d\n",i,j,mul);
}
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
clrscr();
printf("effect of break\n");
for(i=1;i<=5;i++)
{
if(i==2)
break;
printf("%d\n",i);
}
printf("effect of continue\n");
for(i=1;i<=5;i++)
{
if(i==2)
continue;
printf("%d\n",i);
}
getch();
}
44.WAP on multiplication table of a given number
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,mul,j;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=10;j++)
{
mul=i*j;
printf("%d*%d=%d\n",i,j,mul);
}
printf("\n");
}
getch();
}
45.WAP prime number is prime or not from 1 to N
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,c,j;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
printf("prime num from 1 to n num\n");
for(i=1;i<=n;i++)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d\t",i);
}
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,c,j;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
printf("prime num from 1 to n num\n");
for(i=1;i<=n;i++)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d\t",i);
}
getch();
}
46.WAP to print the perfect numbers from 1 to N
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum,i,j;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
printf("perfect numbers from 1 to n\n");
for(i=1;i<=n;i++)
{
sum=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
sum=sum+j;
}
if(sum==i*2)
printf("%d\t",i);
}
getch();
}
47.WAP on sum and average of Array values
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],sum,avg,i;
clrscr();
printf("enter array values\n");
for(i=1;i<=3;i++)
scanf("%d",&a[i]);
for(i=1;i<=3;i++)
sum=sum+a[i];
avg=(float)sum/3;
printf("sum=%d\n avg=%f",sum,avg);
getch();
}
48.WAP to find the max and min vales of array
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20],i,j,n,t;
clrscr();
printf("enter size of array\n");
scanf("%d",&n);
printf("enter array values\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=0;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}}}
printf("min=%d\nmax=%d",a[1],a[n]);
getch();
}
49.WAP on Bubble sort
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20],i,j,n,t;
clrscr();
printf("enter size of array\n");
scanf("%d",&n);
printf("enter array values\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("before sort\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
for(i=0;i<n;i++)
{
for(j=1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("after sort\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
getch();
}
50.WAP on Linear
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20],i,n,se,c=0;
clrscr();
printf("enter size of array\n");
scanf("%d",&n);
printf("array values\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("array values\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
printf("enter serch element\n");
scanf("%d",&se);
for(i=0;i<n;i++)
{
if(a[i]==se)
{
printf("location of serch ele=%d\n",i);
c++;
}
}
if(c==0)
printf("location of serch element not found");
getch();
}
51.WAP on character array
#include<stdio.h>
#include<conio.h>
int main()
{
char a[10],b[10],i;
printf("enter char\n");
for(i=1;i<5;i++)
scanf("%c",&a);
printf("charter arrays\n");
for(i=1;i<5;i++)
printf("%c",a);
getch();
}
52.WAP on string array
#include<stdio.h>
#include<conio.h>
int main()
{
char a[10],b[10];
printf("enter 1st string\n");
scanf("%s",&a);
printf("enter 2nd string\n");
scanf("%s",&b);
printf("total string is %s %s",a,b);
getch();
}
53.WAP on string handling functions
54.WAP on character handiling functions
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
int main()
{
char ch;
clrscr();
printf("enter a char\n");
ch=getchar();
printf("char is=");
putchar(ch);
if(is alpha(ch))
{
if(is upper(ch))
printf("it is upper");
else printf("it is lower");
}
else if(is digit(ch))
printf("it is digit");
else
printf("it is a special charater");
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum,i,j;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
printf("perfect numbers from 1 to n\n");
for(i=1;i<=n;i++)
{
sum=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
sum=sum+j;
}
if(sum==i*2)
printf("%d\t",i);
}
getch();
}
47.WAP on sum and average of Array values
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],sum,avg,i;
clrscr();
printf("enter array values\n");
for(i=1;i<=3;i++)
scanf("%d",&a[i]);
for(i=1;i<=3;i++)
sum=sum+a[i];
avg=(float)sum/3;
printf("sum=%d\n avg=%f",sum,avg);
getch();
}
48.WAP to find the max and min vales of array
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20],i,j,n,t;
clrscr();
printf("enter size of array\n");
scanf("%d",&n);
printf("enter array values\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=0;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}}}
printf("min=%d\nmax=%d",a[1],a[n]);
getch();
}
49.WAP on Bubble sort
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20],i,j,n,t;
clrscr();
printf("enter size of array\n");
scanf("%d",&n);
printf("enter array values\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("before sort\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
for(i=0;i<n;i++)
{
for(j=1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("after sort\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
getch();
}
50.WAP on Linear
#include<stdio.h>
#include<conio.h>
int main()
{
int a[20],i,n,se,c=0;
clrscr();
printf("enter size of array\n");
scanf("%d",&n);
printf("array values\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("array values\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
printf("enter serch element\n");
scanf("%d",&se);
for(i=0;i<n;i++)
{
if(a[i]==se)
{
printf("location of serch ele=%d\n",i);
c++;
}
}
if(c==0)
printf("location of serch element not found");
getch();
}
51.WAP on character array
#include<stdio.h>
#include<conio.h>
int main()
{
char a[10],b[10],i;
printf("enter char\n");
for(i=1;i<5;i++)
scanf("%c",&a);
printf("charter arrays\n");
for(i=1;i<5;i++)
printf("%c",a);
getch();
}
52.WAP on string array
#include<stdio.h>
#include<conio.h>
int main()
{
char a[10],b[10];
printf("enter 1st string\n");
scanf("%s",&a);
printf("enter 2nd string\n");
scanf("%s",&b);
printf("total string is %s %s",a,b);
getch();
}
53.WAP on string handling functions
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char s[20];
int n;
clrscr();
printf("enter a string\n");
gets(s);
printf("str is %s\n",s);
n=strlen("mpcs");
printf("strlen=%d\n",n);
puts(strcat("1st"," year"));
puts(strrev("medem"));
puts(strupr("nani"));
puts(strloor("SHASHI"));
strcpy(s,"smile");
puts(s);
n=strcmp("a","a");
printf("strcmp=%d\n",n);
getch();
}
#include<conio.h>
#include<string.h>
int main()
{
char s[20];
int n;
clrscr();
printf("enter a string\n");
gets(s);
printf("str is %s\n",s);
n=strlen("mpcs");
printf("strlen=%d\n",n);
puts(strcat("1st"," year"));
puts(strrev("medem"));
puts(strupr("nani"));
puts(strloor("SHASHI"));
strcpy(s,"smile");
puts(s);
n=strcmp("a","a");
printf("strcmp=%d\n",n);
getch();
}
54.WAP on character handiling functions
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
int main()
{
char ch;
clrscr();
printf("enter a char\n");
ch=getchar();
printf("char is=");
putchar(ch);
if(is alpha(ch))
{
if(is upper(ch))
printf("it is upper");
else printf("it is lower");
}
else if(is digit(ch))
printf("it is digit");
else
printf("it is a special charater");
getch();
}
55.Palindram string or not
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char a[20],b[20],c[20];
int n;
clrscr();
printf("enter a str\n");
gets(a);
strcpy(b,a);
c=strrev(a);
n=strcmp(b,c);
if(n==0)
printf("it is palindram string");
else
printf("it is not palindram string");
getch();
}
56.WAP on Transpose of matrix
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5][5],nr,nc,i,j;
clrscr();
printf("Enter no.of roos and no.of coloums\n");
scanf("%d%d",&nr,&nc);
printf("Enter array values\n");
for(i=0;i<nr;i++)
{
for(j=0;j<nc;j++)
scanf("%d",&a[i][j]);
}
printf("array values\n");
for(i=0;i<nc;i++)
{
for(j=0;j<nr;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
getch();
}
57.WAP on add of matrix
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5][5],b[5][5],nr,nc,i,j;
clrscr();
printf("Enter no.of roos and no.of coloums\n");
scanf("%d%d",&nr,&nc);
printf("Enter array values of a\n");
for(i=0;i<nr;i++)
{
for(j=0;j<nc;j++)
scanf("%d",&a[i][j]);
}
printf("enter array values of b\n");
for(i=0;i<nr;i++)
{
for(j=0;j<nc;j++)
scanf("%d",&b[i][j]);
}
printf("array values\n");
for(i=0;i<nc;i++)
{
for(j=0;j<nr;j++)
printf("%d\t",(a[i][j]+b[i][j]));
printf("\n");
}
getch();
}
58.WAP on multipication of matrix
#include<stdio.h>
#include<conio.h>
int main()
{
int a[15][15],b[15][15],c[15][15],nr1,nc1,nr2,nc2,i,j,k;
clrscr();
printf("Enter nr1,nr2,nc1 and nc2\n");
scanf("%d%d%d%d",&nr1,&nr2,&nc1,&nc2);
printf("Enter array values of a\n");
for(i=0;i<nr1;i++)
{
for(j=0;j<nc1;j++)
scanf("%d",&a[i][j]);
}
printf("enter array values of b\n");
for(i=0;i<nr2;i++)
{
for(j=0;j<nc2;j++)
scanf("%d",&b[i][j]);
}
printf("multipication matrix\n");
for(i=0;i<nr1;i++)
{
printf("\n");
for(j=0;j<nc2;j++)
{
c[i][j]=0;
for(k=0;k<nc2;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
printf("%d\t",c[i][j]);
}
}
getch();
}
59.WAP on multipication of matrix with checking condision
#include<stdio.h>
#include<conio.h>
int main()
{
int a[15][15],b[15][15],c[15][15],nr1,nc1,nr2,nc2,i,j,k;
clrscr();
mult:
printf("Enter nr1,nr2,nc1 and nc2\n");
scanf("%d%d%d%d",&nr1,&nr2,&nc1,&nc2);
if(nc1==nr2)
{
printf("Enter array values of a\n");
for(i=0;i<nr1;i++)
{
for(j=0;j<nc1;j++)
scanf("%d",&a[i][j]);
}
printf("enter array values of b\n");
for(i=0;i<nr2;i++)
{
for(j=0;j<nc2;j++)
scanf("%d",&b[i][j]);
}
printf("multipication matrix\n");
for(i=0;i<nr1;i++)
{
printf("\n");
for(j=0;j<nc2;j++)
{
c[i][j]=0;
for(k=0;k<nc2;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
printf("%d\t",c[i][j]);
}
}
}
else
{
printf("we can't determine matrix multipication\n");
goto mult;
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char a[20],b[20],c[20];
int n;
clrscr();
printf("enter a str\n");
gets(a);
strcpy(b,a);
c=strrev(a);
n=strcmp(b,c);
if(n==0)
printf("it is palindram string");
else
printf("it is not palindram string");
getch();
}
56.WAP on Transpose of matrix
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5][5],nr,nc,i,j;
clrscr();
printf("Enter no.of roos and no.of coloums\n");
scanf("%d%d",&nr,&nc);
printf("Enter array values\n");
for(i=0;i<nr;i++)
{
for(j=0;j<nc;j++)
scanf("%d",&a[i][j]);
}
printf("array values\n");
for(i=0;i<nc;i++)
{
for(j=0;j<nr;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
getch();
}
57.WAP on add of matrix
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5][5],b[5][5],nr,nc,i,j;
clrscr();
printf("Enter no.of roos and no.of coloums\n");
scanf("%d%d",&nr,&nc);
printf("Enter array values of a\n");
for(i=0;i<nr;i++)
{
for(j=0;j<nc;j++)
scanf("%d",&a[i][j]);
}
printf("enter array values of b\n");
for(i=0;i<nr;i++)
{
for(j=0;j<nc;j++)
scanf("%d",&b[i][j]);
}
printf("array values\n");
for(i=0;i<nc;i++)
{
for(j=0;j<nr;j++)
printf("%d\t",(a[i][j]+b[i][j]));
printf("\n");
}
getch();
}
58.WAP on multipication of matrix
#include<stdio.h>
#include<conio.h>
int main()
{
int a[15][15],b[15][15],c[15][15],nr1,nc1,nr2,nc2,i,j,k;
clrscr();
printf("Enter nr1,nr2,nc1 and nc2\n");
scanf("%d%d%d%d",&nr1,&nr2,&nc1,&nc2);
printf("Enter array values of a\n");
for(i=0;i<nr1;i++)
{
for(j=0;j<nc1;j++)
scanf("%d",&a[i][j]);
}
printf("enter array values of b\n");
for(i=0;i<nr2;i++)
{
for(j=0;j<nc2;j++)
scanf("%d",&b[i][j]);
}
printf("multipication matrix\n");
for(i=0;i<nr1;i++)
{
printf("\n");
for(j=0;j<nc2;j++)
{
c[i][j]=0;
for(k=0;k<nc2;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
printf("%d\t",c[i][j]);
}
}
getch();
}
59.WAP on multipication of matrix with checking condision
#include<stdio.h>
#include<conio.h>
int main()
{
int a[15][15],b[15][15],c[15][15],nr1,nc1,nr2,nc2,i,j,k;
clrscr();
mult:
printf("Enter nr1,nr2,nc1 and nc2\n");
scanf("%d%d%d%d",&nr1,&nr2,&nc1,&nc2);
if(nc1==nr2)
{
printf("Enter array values of a\n");
for(i=0;i<nr1;i++)
{
for(j=0;j<nc1;j++)
scanf("%d",&a[i][j]);
}
printf("enter array values of b\n");
for(i=0;i<nr2;i++)
{
for(j=0;j<nc2;j++)
scanf("%d",&b[i][j]);
}
printf("multipication matrix\n");
for(i=0;i<nr1;i++)
{
printf("\n");
for(j=0;j<nc2;j++)
{
c[i][j]=0;
for(k=0;k<nc2;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
printf("%d\t",c[i][j]);
}
}
}
else
{
printf("we can't determine matrix multipication\n");
goto mult;
}
getch();
}
60.Addition of two numbers
a】function with return type without arrugument
#include<stdio.h>
#include<conio.h>
int add()
{
int a=4,b=7,sum;
sum=a+b;
return sum;
}
void main()
{
int c;
clrscr();
c=add();
printf("sum=%d\n",c);
getch();
}
b】function with arrugument and with return type
#include<stdio.h>
#include<conio.h>
int add(int a,int b)
{
int sum;
sum=a+b;
return sum;
}
int main()
{
int c;
clrscr();
c=add(4,5);
printf("sum=%d\n",c);
getch();
}
c】function without arrugument without return type
#include<stdio.h>
#include<conio.h>
int add()
{
int a=5,b=7,sum;
sum=a+b;
printf("sum=%d\n",sum);
}
void main()
{
int c;
clrscr();
c=add();
getch();
}
d】function with arrugument with out return type
#include<stdio.h>
#include<conio.h>
int add(int a,int b)
{
int sum;
sum=a+b;
printf("sum=%d\n",sum);
}
int main()
{
int c;
clrscr();
c=add(4,5);
getch();
}
61.WAP Division of two integers using function prototype
#include<stdio.h>
#include<conio.h>
int add(int a,int b)
{
float div;
div=a/b;
return div;
}
int main()
{
float c;
clrscr();
c=add(10,5);
printf("div=%f\n",c);
getch();
}
62.Swapping of 2 numbers
a.passing by value
#include<stdio.h>
#include<conio.h>
int swap(int a,int b)
{
int t;
printf("before swape\n a=%d\n b=%d\n",a,b);
a=a+b;
a=a-b;
b=a-b;
printf("after swape\n a=%d\n b=%d",a,b);
}
int main()
{
int c;
clrscr();
c=swap(5,7);
getch();
}
b.passing by reference
#include<stdio.h>
#include<conio.h>
int swap(int &a,int &b)
{
printf("before swape\n a=%d\n b=%d\n",a,b);
a=a+b;
a=a-b;
b=a-b;
printf("after swape\n a=%d\nb=%d",a,b);
}
int main()
{
int a=4,b=7,c;
clrscr();
c=swap(a,b);
getch();
}
63.Factorial & Fibonacci series of a number using recursion
a】function with return type without arrugument
#include<stdio.h>
#include<conio.h>
int add()
{
int a=4,b=7,sum;
sum=a+b;
return sum;
}
void main()
{
int c;
clrscr();
c=add();
printf("sum=%d\n",c);
getch();
}
b】function with arrugument and with return type
#include<stdio.h>
#include<conio.h>
int add(int a,int b)
{
int sum;
sum=a+b;
return sum;
}
int main()
{
int c;
clrscr();
c=add(4,5);
printf("sum=%d\n",c);
getch();
}
c】function without arrugument without return type
#include<stdio.h>
#include<conio.h>
int add()
{
int a=5,b=7,sum;
sum=a+b;
printf("sum=%d\n",sum);
}
void main()
{
int c;
clrscr();
c=add();
getch();
}
d】function with arrugument with out return type
#include<stdio.h>
#include<conio.h>
int add(int a,int b)
{
int sum;
sum=a+b;
printf("sum=%d\n",sum);
}
int main()
{
int c;
clrscr();
c=add(4,5);
getch();
}
61.WAP Division of two integers using function prototype
#include<stdio.h>
#include<conio.h>
int add(int a,int b)
{
float div;
div=a/b;
return div;
}
int main()
{
float c;
clrscr();
c=add(10,5);
printf("div=%f\n",c);
getch();
}
62.Swapping of 2 numbers
a.passing by value
#include<stdio.h>
#include<conio.h>
int swap(int a,int b)
{
int t;
printf("before swape\n a=%d\n b=%d\n",a,b);
a=a+b;
a=a-b;
b=a-b;
printf("after swape\n a=%d\n b=%d",a,b);
}
int main()
{
int c;
clrscr();
c=swap(5,7);
getch();
}
b.passing by reference
#include<stdio.h>
#include<conio.h>
int swap(int &a,int &b)
{
printf("before swape\n a=%d\n b=%d\n",a,b);
a=a+b;
a=a-b;
b=a-b;
printf("after swape\n a=%d\nb=%d",a,b);
}
int main()
{
int a=4,b=7,c;
clrscr();
c=swap(a,b);
getch();
}
63.Factorial & Fibonacci series of a number using recursion
A】Factorial
#include<stdio.h>
#include<conio.h>
int fact(int n)
{
if (n>=1)
return n*fact(n-1);
else
return 1;
}
int main()
{
int n;
printf("Enter positive value\n");
scanf("%d",&n);
printf("Factorial of %d = %d", n, fact(n));
getch();
}
B】Fibonacci Series using Recursion
#include<stdio.h>
#include<conio.h>
int fibo(int n)
{
if (n <= 1)
return n;
return fibo(n-1) + fibo(n-2);
}
int main ()
{
int n;
printf("Enter n value: ");
scanf("%d",&n);
printf("%d\t",fibo(n));
getchar();
getch();
}
64.WAP on pointer &Array
#include<stdio.h>
#include<conio.h>
int main()
{
int a[4]={22,33,44,55}
int *p=a;
printf("%d\n", p);
printf("%d\n", *p);
getch();
}
65.WAP on array name itself as a pointer
#include<stdio.h>
#include<conio.h>
int main()
{
int i,a[5];
clrscr();
printf("Printing elements \n");
for(i=0; i<5;i++)
{
*(a+i)=i;
}
for(i = 0; i < 5; i++)
{
printf("%d\n", *(a + i));
}
getch();
}
66.WAP on array of pointer
#include<stdio.h>
#include<conio.h>
int main()
{
int *p,i=0,sum=0,a[5]={5,6,7,8,9};
clrscr();
p=a;
printf("elements values address\n");
while(5>i)
{
printf("a[%d]%d=%u\n",i,*p,p);
sum=sum+*p;
i++;
p++;
}
printf("\nsum=%d",sum);
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,*p1,*p2,x,y,z;
clrscr();
a=22;
b=5;
p1=&a;
p2=&b;
x=*p1**p2-6;
y=4-*p2/ *p1+10;
printf("address of a=%u\naddress of b=%u",p1,p2);
printf("\na=%d,b=%d\nx=%d,y=%d",a,b,x,y);
*p2=*p2+5;
*p1=*p2-6;
z=*p1**p2-6;
printf("\na=%d,b=%d\nz=%d",a,b,z);
getch();
}
68.WAP on pointer to string
#include<stdio.h>
#include<conio.h>
int main()
{
char *name;
int a;
char *ptr=name;
name="shashi";
while(*ptr!='\o')
{
printf("%c is stored at address %u",*ptr,ptr);
ptr++;
}
a=ptr-name;
printf("length of a string is %d",a);
getch();
}
69.WAP on bubble sort using passing single dimensional array in function
//Well be posted soon
70.wap on bubble sort using passing single dimensional array in function using array name itself as a pointer
//Well be posted soon
71.WAP on structure with three object.
#include<stdio.h>
#include<conio.h>
struct emp
{
char name[20];
int no;
};
int main()
{
struct emp e[3];
int i;
clrscr();
printf("enter emp name &no\n");
for(i=1;i<=3;i++)
scanf("%s%d",&e[i].name,&e[i].no);
printf("emp name & no\n");
for(i=1;i<=3;i++)
printf("%s:%d\n",e[i].name,e[i].no);
getch();
}
72.WAP on array of structure
#include<stdio.h>
#include<conio.h>
struct emp
{
char name[20];
int no;
};
int main()
{
struct emp e;
clrscr();
printf("enter emp name &no\n");
scanf("%s%d",&e.name,&e.no);
printf("emp name & no\n");
printf("%s:%d\n",e.name,e.no);
getch();
}
73.WAP on pointer to structure.
#include<stdio.h>
#include<conio.h>
struct stu
{
char name[20];
int id;
};
int main()
{
struct stu s1,*s2;
clrscr();
s2=&s1;
printf("Enter name & id of student\n");
scanf("%s%d",&s2->name,&s2->id);
printf("stu data\n name=%s\t id==%d\n",s2->name,s2->id);
getch();
}
74.WAP on structure object.
#include<stdio.h>
#include<conio.h>
struct emp
{
char name[20];
int no;
};
int main()
{
struct emp e[3];
int i;
clrscr();
printf("enter emp name &no\n");
for(i=1;i<=3;i++)
scanf("%s%d",&e[i].name,&e[i].no);
printf("emp name & no\n");
for(i=1;i<=3;i++)
printf("%s:%d\n",e[i].name,e[i].no);
getch();
}
75.WAP on passing structure object using
i】pass by value
#include <stdio.h>
#include <string.h>
#include<conio.h>
struct stu
{
int id;
char name[20];
};
void pass(struct stu s)
{
printf(" Id: %d \nName:%s\n", s.id,s.name);
}
int main()
{
struct stu s;
clrscr();
s.id=194;
strcpy(s.name, "shashi");
pass(s);
getch();
}
ii】pass by referenc.
#include <stdio.h>
#include <string.h>
#include<conio.h>
struct stu
{
int id;
char name[20];
}s;
void pass(struct stu *s)
{
printf(" Id: %d \nName:%s\n", s->id,s->name);
}
int main()
{
struct stu s;
clrscr();
s.id=194;
strcpy(s.name, "shashi");
pass(&s);
getch();
}
76.WAP on Nested structure
#include<stdio.h>
#include<conio.h>
struct emp
{
struct dep
{
char name[20];
int no;
}d;
int empno;
}e;
int main()
{
struct emp e;
clrscr();
printf("enter dname,d no, emp no\n");
scanf("%s%d%d",&e.d.name,&e.d.no,&e.empno);
printf("emple data\n");
printf("dname=%s\ndno=%d\n",e.d.name,e.d.no);
printf("emp no=%d",e.empno);
getch();
}
77.WAP on union
#include<stdio.h>
#include<conio.h>
union emp
{
char name[20];
int no;
};
int main()
{
union emp e;
clrscr();
printf("enter emp name &no\n");
scanf("%s%d",&e.name,&e.no);
printf("emp name & no\n");
printf("%s\n%d\n",e.name,e.no);
getch();
}
78.WAP on enumerated data type to display weekdays
#include<stdio.h>
#include<conio.h>
int main()
{
enum week{sun,mon,tue,wen,thu,fri,sat};
clrscr();
printf("sunday=%d\nmonday=%d\n",sun,mon);
printf("Tuesday=%d\nwednesday=%d\n",tue,wen);
printf("thusday=%d\nfriday=%d\n",thu,fri);
printf("saturday=%d",sat);
getch();
}
79.WAP on typedef
#include<stdio.h>
#include<conio.h>
typedef struct student
{
char name[50];
int id;
}stu;
void main( )
{
stu s;
clrscr();
printf("Enter student name and id\n");
scanf("%s%d",&s.name,&s.id);
printf("name is %s\nid=%d",s.name,s.id);
getch();
}
80.WAP on command line Argument
#include<stdio.h>
#include<conio.h>
int main(int argc,char* argv[])
{
clrscr();
printf("Program Name Is: %s\n",argv[0]);
if(argc==1)
printf("\nNo Extra Command Line Argument Passed \n");
if(argc>=2)
{
printf("\nno.of Argum Passed: %d",argc);
printf("\nCommand Line Arguments Passe--");
for(int i=0;i<argc;i++)
printf("\nargv[%d]: %s",i,argv[i]);
}
getch();
}
81.WAP on Macro's
i】simple
#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main()
{
int r=5;
float area;
clrscr();
area=pi*r*r;
printf("area=%f\n",area);
getch();
}
ii】Macro's with arguments
#include<stdio.h>
#include<conio.h>
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b
void main()
{
int a=7,b=4;
clrscr();
printf("max=%d\n",max(a,b));
printf("min=%d\n",min(a,b));
getch();
}
iii】Nesting macros
#include<stdio.h>
#include<conio.h>
#define sq(n) n*n
#define cub(n) sq(n)*n
void main()
{
int n=4;
clrscr();
printf("squre=%d\n",sq(n));
printf("cube=%d\n",cub(n));
getch();
}
82.WAP on storage classes
#include<stdio.h>
#include<conio.h>
int main()
{
auto int a=5;
{
printf("%d\n",a);
auto int a=9;
printf("%d\n",a);
}
getch();
}
83.WAP to creat a file,read a file
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;
char ch;
fp=fopen("shashi","w");
printf("inter the data into file to stope(ctrl+z)");
while((ch==getchar())!=EOF)
putc(ch,fp);
fclose(fp);
fp=fopen("shashi","r");
printf("inter the data into file to stope(ctrl+z)");
while((ch==getc(fp))!=EOF)
putchar(ch);
fclose(fp);
getch();
}
84.WAP to append a file and read a file
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;
char ch;
fp=fopen("shashi","a");
printf("enter the data into file to stope(ctrl+z)");
while((ch==getchar())!=EOF)
putc(ch,fp);
fclose(fp);
fp=fopen("shashi","r");
printf("inter the data into file to stope(ctrl+z)");
printf("\nfile contents\n");
while((ch==getc(fp))!=EOF);
putchar(ch);
fclose(fp);
getch();
}
i】pass by value
#include <stdio.h>
#include <string.h>
#include<conio.h>
struct stu
{
int id;
char name[20];
};
void pass(struct stu s)
{
printf(" Id: %d \nName:%s\n", s.id,s.name);
}
int main()
{
struct stu s;
clrscr();
s.id=194;
strcpy(s.name, "shashi");
pass(s);
getch();
}
ii】pass by referenc.
#include <stdio.h>
#include <string.h>
#include<conio.h>
struct stu
{
int id;
char name[20];
}s;
void pass(struct stu *s)
{
printf(" Id: %d \nName:%s\n", s->id,s->name);
}
int main()
{
struct stu s;
clrscr();
s.id=194;
strcpy(s.name, "shashi");
pass(&s);
getch();
}
76.WAP on Nested structure
#include<stdio.h>
#include<conio.h>
struct emp
{
struct dep
{
char name[20];
int no;
}d;
int empno;
}e;
int main()
{
struct emp e;
clrscr();
printf("enter dname,d no, emp no\n");
scanf("%s%d%d",&e.d.name,&e.d.no,&e.empno);
printf("emple data\n");
printf("dname=%s\ndno=%d\n",e.d.name,e.d.no);
printf("emp no=%d",e.empno);
getch();
}
77.WAP on union
#include<stdio.h>
#include<conio.h>
union emp
{
char name[20];
int no;
};
int main()
{
union emp e;
clrscr();
printf("enter emp name &no\n");
scanf("%s%d",&e.name,&e.no);
printf("emp name & no\n");
printf("%s\n%d\n",e.name,e.no);
getch();
}
78.WAP on enumerated data type to display weekdays
#include<stdio.h>
#include<conio.h>
int main()
{
enum week{sun,mon,tue,wen,thu,fri,sat};
clrscr();
printf("sunday=%d\nmonday=%d\n",sun,mon);
printf("Tuesday=%d\nwednesday=%d\n",tue,wen);
printf("thusday=%d\nfriday=%d\n",thu,fri);
printf("saturday=%d",sat);
getch();
}
79.WAP on typedef
#include<stdio.h>
#include<conio.h>
typedef struct student
{
char name[50];
int id;
}stu;
void main( )
{
stu s;
clrscr();
printf("Enter student name and id\n");
scanf("%s%d",&s.name,&s.id);
printf("name is %s\nid=%d",s.name,s.id);
getch();
}
80.WAP on command line Argument
#include<stdio.h>
#include<conio.h>
int main(int argc,char* argv[])
{
clrscr();
printf("Program Name Is: %s\n",argv[0]);
if(argc==1)
printf("\nNo Extra Command Line Argument Passed \n");
if(argc>=2)
{
printf("\nno.of Argum Passed: %d",argc);
printf("\nCommand Line Arguments Passe--");
for(int i=0;i<argc;i++)
printf("\nargv[%d]: %s",i,argv[i]);
}
getch();
}
81.WAP on Macro's
i】simple
#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main()
{
int r=5;
float area;
clrscr();
area=pi*r*r;
printf("area=%f\n",area);
getch();
}
ii】Macro's with arguments
#include<stdio.h>
#include<conio.h>
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b
void main()
{
int a=7,b=4;
clrscr();
printf("max=%d\n",max(a,b));
printf("min=%d\n",min(a,b));
getch();
}
iii】Nesting macros
#include<stdio.h>
#include<conio.h>
#define sq(n) n*n
#define cub(n) sq(n)*n
void main()
{
int n=4;
clrscr();
printf("squre=%d\n",sq(n));
printf("cube=%d\n",cub(n));
getch();
}
82.WAP on storage classes
#include<stdio.h>
#include<conio.h>
int main()
{
auto int a=5;
{
printf("%d\n",a);
auto int a=9;
printf("%d\n",a);
}
getch();
}
83.WAP to creat a file,read a file
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;
char ch;
fp=fopen("shashi","w");
printf("inter the data into file to stope(ctrl+z)");
while((ch==getchar())!=EOF)
putc(ch,fp);
fclose(fp);
fp=fopen("shashi","r");
printf("inter the data into file to stope(ctrl+z)");
while((ch==getc(fp))!=EOF)
putchar(ch);
fclose(fp);
getch();
}
84.WAP to append a file and read a file
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;
char ch;
fp=fopen("shashi","a");
printf("enter the data into file to stope(ctrl+z)");
while((ch==getchar())!=EOF)
putc(ch,fp);
fclose(fp);
fp=fopen("shashi","r");
printf("inter the data into file to stope(ctrl+z)");
printf("\nfile contents\n");
while((ch==getc(fp))!=EOF);
putchar(ch);
fclose(fp);
getch();
}
86.WAP to copy the current file into new filethen read a copy file
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp,*fp1;
char ch;
fp=fopen("shashi","r");
fp1=fopen("nani","w");
while((ch==getc(fp1))!=EOF)
putc(ch,fp1);
fclose(fp1);
fp1=fopen("nani","r");
printf("\n file contest\n");
while((ch==getc(fp1))!=EOF)
putchar(ch);
fclose(fp1);
getch();
}
87.WAP on Random access file using fseek(), ftell ()
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
FILE *fp;
char ch;
int sz;
clrscr();
fp=fopen("shashi","r");
printf("file contints\n");
while((ch==getc(fp))!=EOF)
putchar(ch);
fseek(fp,0,1,2);
sz=ftell(fp);
printf("\n number of bytes occpied by file=%d\n",sz);
fclose(fp);
getch();
}
88.WAP on creat a file , read file using putw(),getw()
#include <stdio.h>
#include<conio.h>
#include<process.h>
int main ()
{
FILE *fp;
int a=1, b=2, c=3, num;
fp = fopen ("shashi","w");
putw(a,fp);
putw(b,fp);
putw(c,fp);
fclose(fp);
fp = fopen ("shashi","r");
while(getw(fp)!=EOF)
{
num= getw(fp);
printf("Data in test.c file is %d \n",num);
}
fclose(fp);
getch();
}
89.WAP to write a string in file using fprintf(),reading a string from file using fscanf().
#include <stdio.h>
#include<conio.h>
int main ()
{
char name [20];
int age, len;
FILE *fp;
fp = fopen ("shashi","w");
fprintf (fp, "%s %d", "computer science", 5);
len = ftell(fp);
rewind (fp);
fscanf (fp, "%d", &age);
fscanf (fp, "%s", name);
fclose (fp);
printf ("Name:%s\n Age:%d\n",name,age);
printf ("total no of characters in file is %d", len);
getch();
}
90.WAP on Dynamic memory allocation using malloc()#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp,*fp1;
char ch;
fp=fopen("shashi","r");
fp1=fopen("nani","w");
while((ch==getc(fp1))!=EOF)
putc(ch,fp1);
fclose(fp1);
fp1=fopen("nani","r");
printf("\n file contest\n");
while((ch==getc(fp1))!=EOF)
putchar(ch);
fclose(fp1);
getch();
}
87.WAP on Random access file using fseek(), ftell ()
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
FILE *fp;
char ch;
int sz;
clrscr();
fp=fopen("shashi","r");
printf("file contints\n");
while((ch==getc(fp))!=EOF)
putchar(ch);
fseek(fp,0,1,2);
sz=ftell(fp);
printf("\n number of bytes occpied by file=%d\n",sz);
fclose(fp);
getch();
}
88.WAP on creat a file , read file using putw(),getw()
#include <stdio.h>
#include<conio.h>
#include<process.h>
int main ()
{
FILE *fp;
int a=1, b=2, c=3, num;
fp = fopen ("shashi","w");
putw(a,fp);
putw(b,fp);
putw(c,fp);
fclose(fp);
fp = fopen ("shashi","r");
while(getw(fp)!=EOF)
{
num= getw(fp);
printf("Data in test.c file is %d \n",num);
}
fclose(fp);
getch();
}
89.WAP to write a string in file using fprintf(),reading a string from file using fscanf().
#include <stdio.h>
#include<conio.h>
int main ()
{
char name [20];
int age, len;
FILE *fp;
fp = fopen ("shashi","w");
fprintf (fp, "%s %d", "computer science", 5);
len = ftell(fp);
rewind (fp);
fscanf (fp, "%d", &age);
fscanf (fp, "%s", name);
fclose (fp);
printf ("Name:%s\n Age:%d\n",name,age);
printf ("total no of characters in file is %d", len);
getch();
}
#include <stdio.h>
#include <conio.h>
#include<process.h>
int main()
{
int n=6,i;
int* p;
printf("Number of elements: %d\n",n);
p= (int*)malloc(n, sizeof(int));
if (p == NULL)
{
printf("Memory not allocated.\n");
exit(0);
}
else {
printf("successfully memory is allocated \n");
for (i = 0; i < n; ++i)
p[i] = i + 1;
printf("Elements of the array is\n");
for (i = 0; i < n; ++i)
printf("%d", p[i]);
}
getch();
}
**🙏...Thanks for watching...🙏**
Comments