Sei sulla pagina 1di 62

1.

ADDITION OF TWO NO:

#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.

ROOTS OF A QUADRATIC EQUATION:

#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;

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

4.

FACTORIAL OF A NO:

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

5.

TABLE OF A NO:

#include<conio.h>
#include<stdio.h>
void main()
{
int x,y,y1;
x=0;
y=0;
clrscr();
printf("enter the no y");
scanf("%d",&y);
printf("the table of %d is\n",y);
while(x<10)
{
y1=y*(x+1);
printf("the element %d is %d\n",x+1,y1);
x=x+1;
}
getch();
}

6.

FACTORIAL OF FIRST 10 NATURAL NO:

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

7.

FABNOCCI SERIES:

#include<stdio.h>

#include<conio.h>
void main()
{
int x,y,y1,y2,y3;
clrscr();
y1=0;
y2=1;
y3=0;
printf("the element of fabnocci series is %d\n",y1);
printf("the element of fabnocci series is %d\n",y2);

for(y=0;y<20;y++)
{
y3=y1+y2;
y1=y2;
y2=y3;
printf("the element of fabnocci series is %d\n",y2);
}
getch();
}

8.

PRIME NO:

#include<stdio.h>

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

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

void main()
{
float x,y,m1,m2,c1,c2;
clrscr();
printf("enter the value of m1");
scanf("%f",&m1);
printf("enter the value of m2");
scanf("%f",&m2);
printf("enter the value of c1");
scanf("%f",&c1);
printf("enter the value of c2");
scanf("%f",&c2);
x=(c2-c1)/(m1-m2);
y=(m1c2-m2c1)/(m1-m2);
printf(the point of intersection of lines is %f,%f,x,y);
getch();
}

10.

INCREMENT OF A NO(WHILE LOOP):

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

x=0;
clrscr();
while(x<10)
{
printf(the value of x is %d\n,x);
x=x+1;
}
getch();
}

11.

SUM OF FIRST TEN NATURAL NO:

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int x,sum;
x=0;
sum=0;

clrscr();
while(x<10)
{
sum=sum+x;
x=x+1;
}
printf(the sum of first ten no is %d,sum);
getch();
}

12.

AREA OF CIRCLE:

#include<stdio.h>
#include<conio.h>
void main()
{
int r,a;
clrscr();
printf("enter the value of r");
scanf("%f",&r);
a=3.14*r*r;
printf(the area of circle is %d,a);

getch();
}

13.

CIRCUMFERENCE OF A CIRCLE:

#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
printf("enter the radius of circle r");
scanf("%f",&r);
a=2*3.14*r;
printf(the circumference of circle is %d,c);
getch();
}

14.

AREA OF SQUARE:

#include<stdio.h>
#include<conio.h>
void main()
{
int r,a;
clrscr();
printf("enter the length of square r");
scanf("%f",&r);
a=r*r;
printf(the area of square is %d,a);
getch();
}

15.

AREA OF RECTANGLE:

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

16.

AREA OF TRIANGLE:

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

17.

PRIME NO.:

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,n,status=0;
clrscr();
printf("enter the no n");
scanf("%d",&n);

for(x=2;x<n;x++)
{
y=n%x;
if(y==0)
{
status=1;

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

18.

PRIME NUMBERS UPTO 100:

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

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

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];
}
}
printf("the max value in the array is %d",max);
getch();
}

22.

SECOND LARGEST NO USING ARRAY:

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

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

23.

THIRD LARGEST NO USING ARRAY:

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

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

24. REVERSE
VALUES:

PRINTING OF ENTERED

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

25.

SIZE OF ARRAY:

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

26. SEARCHING THE LOCATION OF NO.


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

getch();
}

27. SEARCHING THE LOCATION OF NO IN


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

28.

SORTING:

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

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

29.

2-D ARRAY:

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

int i,j,x[3][3];
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("enter the elements of row x[%d][%d]",i,j);
scanf("%d",&x[i][j]);
}

}
for(i=0;i<3;i++)
{
printf(" %d %d %d\n",x[i][0],x[i][1],x[i][2]);
}
getch();
}

30.

ADDITION OF MATRICES:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,m,n,a,b,z[3][3],x[3][3],y[3][3];

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

{
for(b=0;b<3;b++)
{
z[a][b]=x[a][b]+y[a][b];
}
}
for(a=0;a<3;a++)
{
printf("the addition of matrices is %d %d %d\n",z[a][0],z[a][1],z[a][2]);
}
getch();
}

31. TRANSPOSE OF MATRIX :


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,x[3][3],swap;
clrscr();
for(i=0;i<3;i++)

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

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

p=&x;
p1=&x1;
printf("the address of x & x1 is %u & %u",p,p1);
getch();
}

33. DIFFERENCE IN ADDRESS OF ARRAY


ELEMENTS:
#include<stdio.h>
#include<conio.h>
void main()
{
float *p1,*p2;
unsigned int i;
float x[3],difference;
clrscr();
for(i=0;i<3;i++)

{
printf("enter the value of x[%u]",i);
scanf("%f",&x[i]);
}
p1=&x[0];
p2=&x[1];
difference=p2-p1;
printf("the differnce in address of x[0] & x[1] is %f\n",difference);
printf("the address of x[0] & x[1] is %u & %u",p1,p2);
getch();
}

34.
#include<stdio.h>
#include<conio.h>
void main()
{
char *p1,*p2;
unsigned int i,difference;
char x[3];
clrscr();
for(i=0;i<3;i++)
{

printf("enter the value of x[%u]",i);


scanf("%c",&x[i]);
//x[i]=getch();
}
p1=&x[0];
p2=&x[1];
difference=p2-p1;
printf("the differnce in address of x[0] & x[1] is %u\n",difference);
printf("the address of x[0] & x[1] is %u & %u",p1,p2);
getch();
}

35.

MAX NO USING POINTERS:

#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int *p;
unsigned int i,x[10],max;
clrscr();
for(i=0;i<10;i++)
{
printf("enter the values of x[%u]",i);
scanf("%u",&x[i]);

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

36.

SUM OF ARRAY USING POINTERS:

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

for(i=0;i<10;i++)
{
sum=sum+*p;
p=p+1;
}
printf("the sum of array is %u\n",max);
getch();
}

37.

FUNCTIONS:

#include<stdio.h>
#include<conio.h>
int maxarray(unsigned int *,int); //int=written type of function
//main program:
void main()
{
//unsigned int *p;
unsigned int i,x[10],max;
clrscr();
for(i=0;i<10;i++)
{
printf("enter the values of x[%u]",i);
scanf("%u",&x[i]);
}

//calling of function

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

38.

ADDITION OF ARRAY USING FUNTIONS:

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

int summation(unsigned int *p,int sizeofarray)


{
int i,sum;
for(i=0;i<sizeofarray;i++)
{
sum=sum+*p;
p=p+1;
}
return(sum);
}

39.

FACTORIAL OF NO. USING FUNCTIONS:

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

{
f=f*p;
p=p-1;
}
return(f);
}

40.

PRIME NO:

#include<stdio.h>
#include<conio.h>
int primeno(unsigned int);

void main()
{
unsigned int x,n,p;
clrscr();
for(x=2;x<n;x++)
{
printf("enter the value of n");
scanf("%u",&n);
}
p=primeno(n);
printf(" the prime no is %u\n",p);
getch();
}

int primeno(unsigned int p)

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

return(p);
}

41. SUMMATION OF ARRAY USING


FUNCTIONS:
#include<stdio.h>
#include<conio.h>
int summation(int *,int,float *);

void main()
{
int x[10],i,sum;
float average;
clrscr();
for(i=0;i<10;i++)
{
printf("enter the value of x[%d]",i);
scanf("%d",&x[i]);
}
sum=summation(&x[0],10,&average);
printf("the summation of array is %d\n",sum);

printf("the average of array is %f",average);


getch();

int summation(int *x,int sizeofarray,float *avg)


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

42.

COMPARING

STRINGS:

#include<stdio.h>
#include<conio.h>
#include<string.h>
int compare_strings(char [], char []);
void main()
{
char a[10], b[10];
int flag;
clrscr();
printf("enter the first string\n");
gets(a);

printf("enter the second string\n");


gets(b);

flag=compare_strings(a,b);

if(flag==0)
{
printf("entered strings are equal\n");
}
else

{
printf("entered strings are not equal\n");
}
getch();
}

int compare_strings(char a[], char b[])


{
int c=0;
while(a[c]==b[c])
{
if(a[c]=='\0' || b[c]=='\0')
{
c++;
break;
}
if(a[c]=='\0' && b[c]=='\0')
{
return 0;
}
else
{
return -1;
}

return 0;
}

43.

STRUCTURES:

#include<stdio.h>
#include<conio.h>
void main()
{
struct book
{
char name[10];
float price;
int pages;
};
clrscr();
struct book b1,b2;

printf("Enter name, price and no. of pages of 2 books\n");

scanf("%s %f %d",&b1.name,&b1.price,&b1.pages);
scanf("%s %f %d",&b2.name,&b2.price,&b2.pages);

printf(" this is what you entered\n");

printf("%s %f %d\n",b1.name,b1.price,b1.pages);
printf("%s %f %d\n",b2.name,b2.price,b2.pages);
getch();
}

44.

ARRAY OF STRUCTURES:

#include<stdio.h>
#include<conio.h>
#include<string.h>
int linkfloat();
void main()
{
struct book
{
char name[20];
float price;
int pages;
};

struct book b[10];


int i;
clrscr();

for(i=0;i<5;i++)
{
printf("Enter name,price and pages\n");
fflush(stdin);

//used to free the memory

scanf("%s %f %d",&b[i].name,&b[i].price,&b[i].pages);
}

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

printf("%s %f %d\n",b[i].name,b[i].price,b[i].pages);
}

getch();
}
int linkfloat()
{
float a=0,*b;
b=&a;
a=*b;
return 0;
}

Potrebbero piacerti anche