You are on page 1of 62

# 1.

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
clrscr();
printf(“enter the no x”);
scanf(“%d”,&x);
printf(“enter the no y”);
scanf(“%d”,&y);
z=x+y;
printf(“the addition of %d and %d is %d”,x,y,z);
getch();
}

2.

CONDITION: if and else

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf(“the amount of x”);
scanf(“%d”,&x);
if(x<60000 && x>=500)
{
printf(“the online transaction is safe”);
}
else
{
printf(“the online transaction is not safe or invalid”);
}
getch();
}

3.

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float x,y,z,a,b,c,s1,s2,i;
clrscr();
printf("enter the value of a");
scanf("%f",&a);
printf("enter the value of b");
scanf("%f",&b);
printf("enter the value of c");
scanf("%f",&c);
x=b*b;
y=4*a*c;
z=2*a;
if(x-y>0)
{
printf("the roots are real and distinct");
s1=(-b+sqrt(x-y))/z;
s2=(-b-sqrt(x-y))/z;

} if(x-y<0) { printf("the roots are complex\n\n"). s1=-b/z.s2). printf("%f\n".s1). s2=sqrt(y-x)/z.s2).s2). } if(x-y==0) { printf("the roots are real and equal").printf("%f\n". printf("%f + i %f\n".s1. s1=-b/z. } getch(). printf("%f .i %f\n". } . printf("%f\n".s1).s1.

} .n. } printf("the factorial of %d is %d".h> void main() { int x. clrscr().f. FACTORIAL OF A NO: #include<stdio. x=x-1. { f=f*x. getch().&n). while(x>1). printf("enter the value of n").n. f=1.h> #include<conio. scanf("%d".4. x=n.f).

} 6. x=0.y).y1.5. } getch().h> #include<stdio. scanf("%d". printf("the element %d is %d\n". TABLE OF A NO: #include<conio. FACTORIAL OF FIRST 10 NATURAL NO: . clrscr().h> void main() { int x.y1). x=x+1. while(x<10) { y1=y*(x+1). y=0. printf("the table of %d is\n".y. printf("enter the no y").&y).x+1.

} printf("the factorial of %u is %u\n". } 7. clrscr().x>1.h> void main() { unsigned int x.y++) { y1=1.y. FABNOCCI SERIES: #include<stdio.#include<stdio. } getch(). for(y=1.y1).h> .x--) { y1=y1*(x-1).y. for(x=y+1.y<9.y1.h> #include<conio.

for(y=0. } 8.h> . y2=y3. } getch(). printf("the element of fabnocci series is %d\n".y1.h> void main() { int x.y<20.y++) { y3=y1+y2. y1=0.#include<conio. clrscr().y2.y3. PRIME NO: #include<stdio. y1=y2. printf("the element of fabnocci series is %d\n".y2). y3=0.y. printf("the element of fabnocci series is %d\n".y1). y2=1.y2).

clrscr(). for(x=2.#include<conio.n. } .x++) { y=n/x. } } getch().&n). printf("enter the no n").x<n. if(y) { printf("the no is not prime no"). scanf("%d".h> void main() { int x. } else { printf("the no is prime no").y.

h> #include<math.9. INTERSECTION OF TWO STRAIGHT LINES: #include<stdio.h> #include<conio.h> .

&m2).h> #include<conio.m2.m1.y. scanf("%f". .c2.y). printf("enter the value of c1").void main() { float x. printf("enter the value of m1"). scanf("%f". x=(c2-c1)/(m1-m2). y=(m1c2-m2c1)/(m1-m2).h> void main() { int x.x. INCREMENT OF A NO(WHILE LOOP): #include<stdio.c1. getch(). printf(“the point of intersection of lines is %f.%f”.&m1). } 10.&c2). clrscr(). scanf("%f".&c1). printf("enter the value of c2"). printf("enter the value of m2"). scanf("%f".

clrscr(). SUM OF FIRST TEN NATURAL NO: #include<stdio.x). sum=0.h> void main() { int x.h> #include<conio. x=0.x=0. . } 11. while(x<10) { printf(“the value of x is %d\n”.h> #include<math. x=x+1. } getch().sum.

.h> #include<conio. } printf(“the sum of first ten no is %d”. a=3. printf(“the area of circle is %d”. AREA OF CIRCLE: #include<stdio.&r).clrscr().a). getch(). x=x+1.a.14*r*r. printf("enter the value of r").sum). clrscr(). scanf("%f". while(x<10) { sum=sum+x. } 12.h> void main() { int r.

a=2*3. scanf("%f". } 13.&r).c.h> #include<conio.h> void main() { int r.c). getch(). printf("enter the radius of circle r").14*r. clrscr().getch(). printf(“the circumference of circle is %d”. } . CIRCUMFERENCE OF A CIRCLE: #include<stdio.

} . getch(). AREA OF SQUARE: #include<stdio. clrscr(). a=r*r.a. scanf("%f". printf("enter the length of square r").h> void main() { int r.h> #include<conio. printf(“the area of square is %d”.14.&r).a).

scanf("%f".b. } .15.h> #include<conio.&l).a). getch(). AREA OF RECTANGLE: #include<stdio. scanf("%f".a. clrscr().&b). a=l*b. printf(“the area of rectangle is %d”. printf("enter the breadth of rectangle b"). printf("enter the length of rectangle l").h> void main() { int l.

h> #include<conio. a=l*b/2. scanf("%f". scanf("%f". getch(). } .&h). printf("enter the base of triangle b").b. printf("enter the height of triangle h").&b). clrscr().h> void main() { int h.a.a). printf(“the area of triangle is %d”. AREA OF TRIANGLE: #include<stdio.16.

clrscr(). for(x=2.h> #include<conio. PRIME NO.x<n.y.x++) { y=n%x.&n).n. scanf("%d".: #include<stdio. printf("enter the no n"). if(y==0) { status=1.status=0.17.h> void main() { int x. .

} } if(status==1) { printf("the no is not prime no"). } getch(). } . } else { printf(“the no is prime no”).

x--) { y=n%x.x>1. } } .18. if(y==0) { break.n++) { for(x=n-1.h> void main() { int x.h> #include<conio. clrscr().n<100. for(n=2. PRIME NUMBERS UPTO 100: #include<stdio.n.y.

} } getch().if(y!=0) { printf("the prime no is %d\n".n). } .

19.

SUM OF NO USING ARRAY:

# include <stdio.h>
# include <conio.h>
void main()
{
int x[10],i,sum;
clrscr();
for(i=0;i<10;i++)
{
printf("Enter the value of x[%d]",i);
scanf("%d",&x[i]);
}
for(i=0;i<10;i++)
{
sum=sum+x[i];
}
printf("the sum of x[%d]=%d \n",i,sum);
getch();

}

20.

AVERAGE OF NO USING ARRAYS:

# include <stdio.h>
# include <conio.h>
void main()
{
int x[10],i,sum;
clrscr();
for(i=0;i<10;i++)
{
printf("Enter the value of x[%d]",i);
scanf("%d",&x[i]);
}
for(i=0;i<10;i++)
{
sum=sum+x[i];
}
average=float(sum)/10;
printf("the average is %d”,average);

getch();
}

21.

MAX VALUE IN AN ARRAY:

# include <stdio.h>
# include <conio.h>
void main()
{
int x[10],i,max;
clrscr();
for(i=0;i<10;i++)
{
printf("Enter the value of x[%d]",i);
scanf("%d",&x[i]);
}
max=x[0];
for(i=0;i<10;i++)
{
if(max<x[i])
{

max=x[i]. } .max). } } printf("the max value in the array is %d". getch().

i). clrscr().22.i++) { printf("Enter the value of x[%d]". } max=x[0].max.i<10. for(i=0. index=0. .m2.&x[i]).i. scanf("%d". SECOND LARGEST NO USING ARRAY: # include <stdio.index.i++) { if(max<x[i]) { max=x[i].i<10.h> void main() { int x[10].h> # include <conio. for(i=0.

i<10. index=0. getch(). } . for(i=0. } } printf("the second largest value in the array is %d". index=i.index=i.max).i++) { if(max<x[i]) { max=x[i]. } } x[index]=0. max=x[0].

23.&x[i]). index=0. index=i.max. } } x[index]=0. .i<10. scanf("%d".i++) { printf("Enter the value of x[%d]". max=x[0]. THIRD LARGEST NO USING ARRAY: # include <stdio. clrscr().h> void main() { int x[10].i<10. for(i=0.i).i++) { if(max<x[i]) { max=x[i]. } max=x[0].i. for(i=0.h> # include <conio.index.

i++) { if(max<x[i]) { max=x[i]. for(i=0. for(i=0. } . getch().i++) { if(max<x[i]) { max=x[i]. } } printf("the third largest value in the array is %d". } } x[index]=0.i<10.i<10. index=i.index=0. index=0.max). index=i. max=x[0].

y[10].i++) { printf("Enter the value of x[%d]". clrscr().y[j]).j++) { printf("the value of y[%d] is %d\n". } .j++) { y[9-j]=x[j]. } getch(). } for(j=0.i). REVERSE VALUES: PRINTING OF ENTERED # include <stdio.j<i.i<10.j.i. for(i=0.&x[i]).j.h> # include <conio. } for(j=0.j<10.h> void main() { int x[10]. scanf("%d".24.

printf("the size of x is %d". clrscr(). scanf("%d".i<j.i.&x[i]).i). j=sizeof(x). } getch().25.h> void main() { int x[3]. for(i=0.j.i++) { printf("Enter the value of x[%d]".h> # include <conio.j). } . SIZE OF ARRAY: # include <stdio.

scanf("%d".y.index. for(i=0. .h> # include <conio. clrscr().j. SEARCHING THE LOCATION OF NO. } } printf("the location of no is %d". WHICH IS NOT IN ARRAY: # include <stdio. index=-1.26.index).i++) { printf("Enter the value of x[%d]". scanf("%d". for(i=0.i<k.&x[i]). } printf("the no to be searched is ").&y). break.i.i++) { if(y==x[i]) { index=i.i<10.i). k=sizeof(x)/2.h> void main() { int k.x[10].

} .getch().

for(i=0.h> void main() { int x[10].i++) { printf("Enter the value of x[%d]".i.i). SEARCHING THE LOCATION OF NO IN ARRAY: # include <stdio. for(i=0.index).i<10. .j.&x[i]). getch().index. clrscr().h> # include <conio.27. } } printf("the location of no is %d".&y). } printf("the no to be searched is "). break.i++) { if(y==x[i]) { index=i.i<10. scanf("%d".y. index=-1. scanf("%d".

} 28.h> . SORTING: #include<stdio.h> #include<conio.

scanf("%d".i++) { printf("the descending series is %d\n".j.x[i]).i<9.void main() { int i.i<10. x[j+1]=swap. } getch(). } for(i=0.&x[i]).x[10].i).j++) { if(x[j]<x[j+1]) { swap=x[j].i++) { for(j=0. x[j]=x[j+1]. .swap. clrscr().j<9-i. } } } for(i=0. for(i=0.i<10.i++) { printf("enter the value of x[%d]".

h> #include<conio.} 29.h> void main() { . 2-D ARRAY: #include<stdio.

h> #include<conio.j.x[i][1].x[3][3].j++) { printf("enter the elements of row x[%d][%d]".x[3][3]. scanf("%d".i.h> void main() { int i.n. clrscr(). for(i=0.b.x[i][0]. .&x[i][j]).i<3.z[3][3].i++) { printf(" %d %d %d\n".int i.m.j. } } for(i=0. ADDITION OF MATRICES: #include<stdio.j).x[i][2]).y[3][3].i<3.i++) { for(j=0. } getch(). } 30.j<3.a.

n++) { printf("enter the element of row y[%d][%d]". } } for(m=0.&x[i][j]).j).&y[m][n]).x[i][1]. scanf("%d".i<3.y[m][1].i.m<3. } } for(i=0.m.j++) { printf("enter the element of row x[%d][%d]". for(i=0.i++) { printf("%d %d %d\n".n).m++) { printf("%d %d %d\n".clrscr().a++) .x[i][2]). scanf("%d".m<3.i<3.a<3.y[m][0]. } for(m=0.i++) { for(j=0.m++) { for(n=0.j<3.n<3.y[m][2]). } for(a=0.x[i][0].

z[a][0].j.h> void main() { int i.z[a][2]).a++) { printf("the addition of matrices is %d %d %d\n".b++) { z[a][b]=x[a][b]+y[a][b].x[3][3].i<3. } } for(a=0.b<3. for(i=0. TRANSPOSE OF MATRIX : #include<stdio.i++) . } 31.a<3.z[a][1].{ for(b=0.h> #include<conio.swap. } getch(). clrscr().

i=j.j).j<3. } } for(i=0.i++) { for(j=0.i++) { printf("%d %d %d\n".i. } for(i=0.x[2][i]). } } printf("the transpose of matrix is \n").i<3.i<3.j++) { printf("enter the element of row x[%d][%d]".x[i][2]).x[1][i]. for(i=0. scanf("%d".x[0][i]. .x[i][0].j++) { swap=i.{ for(j=0.i<3. } getch(). j=swap.i++) { printf("%d %d %d\n".j<3.&x[i][j]).x[i][1].

} 32.&x. unsigned int x. printf("enter the value of x. .&x1). clrscr(). x1.h> #include<conio.*p1.x1").h> void main() { unsigned int *p. POINTERS: #include<stdio. scanf("%u %u".

printf("the address of x & x1 is %u & %u".difference. p1=&x1. } 33.h> void main() { float *p1.i<3.p=&x. for(i=0.*p2. getch().p. float x[3]. clrscr().p1). DIFFERENCE IN ADDRESS OF ARRAY ELEMENTS: #include<stdio. unsigned int i.h> #include<conio.i++) .

&x[i]). scanf("%f".i<3.h> #include<conio. difference=p2-p1.i).h> void main() { char *p1.p2).{ printf("enter the value of x[%u]". } p1=&x[0].difference).*p2.p1. char x[3]. printf("the differnce in address of x[0] & x[1] is %f\n". } 34. clrscr(). getch().difference.i++) { . printf("the address of x[0] & x[1] is %u & %u". p2=&x[1]. for(i=0. unsigned int i. #include<stdio.

difference=p2-p1.i). unsigned int i.difference). getch().x[10].i). for(i=0.p2). scanf("%c". clrscr(). printf("the differnce in address of x[0] & x[1] is %u\n". printf("the address of x[0] & x[1] is %u & %u".&x[i]).max. scanf("%u". . //x[i]=getch(). p2=&x[1]. } 35.printf("enter the value of x[%u]".p1. } p1=&x[0].&x[i]).h> void main() { unsigned int *p.i++) { printf("enter the values of x[%u]". MAX NO USING POINTERS: #include<stdio.h> #include<conio.i<10.

getch(). for(i=0.} p=&x[0]. max=*p.i++) { if(max<*p) { max=*p.max). } printf("the maximum value in array is %u\n". } p=p+1.i<10. } .

. clrscr().max. SUM OF ARRAY USING POINTERS: #include<stdio.h> void main() { unsigned int *p.i++) { printf("enter the values of x[%u]".h> #include<conio.x[10]. scanf("%u". } p=&x[0].i).36.&x[i]). unsigned int i. for(i=0.i<10.

max.max).i<10.h> #include<conio. } printf("the sum of array is %u\n".x[10].for(i=0.i). clrscr(). FUNCTIONS: #include<stdio. } //calling of function . getch().i++) { sum=sum+*p. scanf("%u".i<10. p=p+1.&x[i]).h> int maxarray(unsigned int *.int). //int=written type of function //main program: void main() { //unsigned int *p. } 37.i++) { printf("enter the values of x[%u]". unsigned int i. for(i=0.

i++) { if(max<*p) { max=*p.max.10). for(i=0.max). max=*p. } p=p+1. int sizeofarray) //(argument of function) { //p=&x[0]. } .i<sizeofarray. } //sub program/body: int maxarray(unsigned int *p. } return(max). int i.max=maxarray(&x[0]. getch(). printf("the maximum value in array is %u\n".

scanf("%u". getch().i++) { printf("enter the value of x[%u]".10). ADDITION OF ARRAY USING FUNTIONS: #include<stdio.int).x[10].sum. for(i=0.sum). } . printf("the summation of array is %u\n".h> int summation(unsigned int *. } sum=summation(&x[0].38. clrscr().&x[i]). void main() { unsigned int i.i).i<10.h> #include<conio.

i++) { sum=sum+*p.i<sizeofarray. for(i=0. } .sum.int sizeofarray) { int i. p=p+1. } return(sum).int summation(unsigned int *p.

FACTORIAL OF NO.f.f). f=factorial(n). printf("enter the value of n"). scanf("%u". getch(). printf("the factorial is %u".h> int factorial(unsigned int). clrscr(). void main() { unsigned int x. while(p>1) . } int factorial(unsigned int p) { int f.n.39. USING FUNCTIONS: #include<stdio.&n).h> #include<conio. f=1.

} int primeno(unsigned int p) .p. } return(f).x++) { printf("enter the value of n"). PRIME NO: #include<stdio.&n). } p=primeno(n). getch(). scanf("%u".p). for(x=2.x<n.{ f=f*p. p=p-1. void main() { unsigned int x.h> int primeno(unsigned int). } 40. printf(" the prime no is %u\n".h> #include<conio.n. clrscr().

} .y. } } if(y!=0) { printf("the prime no is %u\n".p).x<n.n.x++) { y=n%x.{ unsigned int x. if(y==0) { break. for(x=2. } return(p).

void main() { int x[10]. for(i=0.sum.int. .h> int summation(int *.i. clrscr(). getch(). scanf("%d".h> #include<conio.average).&x[i]).10.i). SUMMATION OF ARRAY USING FUNCTIONS: #include<stdio. } sum=summation(&x[0]. printf("the average of array is %f".i++) { printf("enter the value of x[%d]". printf("the summation of array is %d\n". float average.i<10.float *).41.sum).&average).

i.} int summation(int *x.int sizeofarray.i<sizeofarray.i++) { sum=sum+x[i]. for(i=0. return(sum). } . } *avg=float(sum)/10.float *avg) { int sum. sum=0.

h> #include<conio. int flag.h> #include<string. gets(a). } else . void main() { char a[10]. COMPARING STRINGS: #include<stdio.42. if(flag==0) { printf("entered strings are equal\n"). printf("enter the first string\n"). flag=compare_strings(a.b). clrscr(). gets(b). printf("enter the second string\n"). b[10].h> int compare_strings(char []. char []).

break. char b[]) { int c=0. } getch(). while(a[c]==b[c]) { if(a[c]=='\0' || b[c]=='\0') { c++. } else { return -1. } if(a[c]=='\0' && b[c]=='\0') { return 0. } } .{ printf("entered strings are not equal\n"). } int compare_strings(char a[].

} .return 0.

price. ARRAY OF STRUCTURES: .pages). clrscr(). scanf("%s %f %d". }.&b2.b2. scanf("%s %f %d". int pages.h> #include<conio. printf("%s %f %d\n". printf("%s %f %d\n".h> void main() { struct book { char name[10].pages).&b2. price and no.b1.name.&b1.price.name. getch().b2.&b2. of pages of 2 books\n"). printf(" this is what you entered\n").&b1.price.43.b1.pages). struct book b1. float price.&b1.b2.name.price. STRUCTURES: #include<stdio. printf("Enter name.name. } 44.pages).b1.b2.

int i.price.h> #include<conio. int pages.&b[i]. float price.h> #include<string.i<5.price and pages\n").i++) { printf("Enter name. fflush(stdin). for(i=0.name.pages).h> int linkfloat(). } for(i=0. }.i++) { .&b[i].i<5. void main() { struct book { char name[20]. //used to free the memory scanf("%s %f %d".&b[i]. struct book b[10].#include<stdio. clrscr().

b[i]. } getch().pages).b[i]. } int linkfloat() { float a=0.name. b=&a.*b. return 0. } .b[i].printf("%s %f %d\n". a=*b.price.