Download as pdf or txt
Download as pdf or txt
You are on page 1of 60

1.PROGRAM TO FIND THE LARGEST OF TWO NUMBERS.

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,large;
clrscr();
printf("enter two number");
scanf("%d%d",&a,&b);
if(a>b)
{
large=a;
}
else
{
large=b;
}
printf("largest number is:%d",large);
getch();
return 0;
}
OUTPUT
2.SUM OF NUMBER LESS THAN N
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,sum=0;
clrscr();
printf("Enter the number");
scanf("%d",&n);
for(i=1;i<n;i++)
{
sum=sum+i;
}
printf("sum of number less than n%d",sum);
getch();
return 0;
}

OUTPUT
3.PROGRAM TO FIND SUM OF THE DIGITS OF A
NUMBER.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,rem,sum=0;
printf("Enter the number");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("sum of the digits of the given number is %d",sum);
getch();
return 0;
}

OUTPUT
4.PROGRAM TO FIND WEATHER THE GIVEN NUMBER IS
ARMSTRONG OR NOT.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,rem,temp,sum=0;
clrscr();
printf("enter the number");
scanf("%d",&n);
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+(rem*rem*rem);
n=n/10;
}
if(sum=temp)
{
printf("the given number is armstrong");
}
else
{
printf("the given number is not armstrong");
}
getch();
return 0;
}

OUTPUT
5. PROGRAM TO FIND WEATHER THE GIVEN NUMBER IS
EVEN OR ODD.
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
clrscr();
printf("enter the number");
scanf("%d",&n);
if(n%10==0)
{
printf("the given number is even");
}
else
{
printf("the given number is odd");
}
getch();
return 0;

}
OUTPUT.
6.PROGRAM TO GENERATE FIBONACCI SERIES.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,n,i;
clrscr();
printf("enter the number of terms");
scanf("%d",&n);
a=0;
b=1;
c=0;
printf("fibonacii terms = \n");
for(i=1;i<=n;i++)
{
printf("%d",&n);
a=b;
b=c;
c=a+b;
}
getch();
return 0;
}
OUTPUT.
7.PROGRAM TO CHECK PRIME OR NOT.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,y=0;
clrscr();
printf("enter the number" );
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
y=1;
break;
}
}
if(y==1)
{
printf("the given number is not prime");
}
else
{
printf("the given number is prime");
}
getch();
return 0;
}

OUTPUT.
8.PROGRAM TO REVERSE THE GIVEN NUMBER.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,rem,sum=0;
clrscr();
printf("enter the number ");
scanf("%d", &n);
while(n>0)
{
rem=n%10;
sum=sum*10+rem;
n=n/10;
}
printf("the reverse of the given number is %d",sum);
getch();
return 0;
}

OUTPUT
9.CALCULATOR PROGRAM
#include<stdio.h>
#include<conio.h>
int main()
{
float a,b,res=0;
char op;
clrscr();
printf("enter the value of a and b");
scanf("%f %f",&a,&b);
printf("enter the operation to be performed:+,-,*,/");
scanf(" %c",&op);

switch(op)
{
case '+':res=a+b;
break;
case '-':res=a-b;
break;
case '*':res=a*b;
break;
case '/':res=a/b;
break;

default:printf("ERROR:invaild operation");
}
printf("result=%2f",res);
getch();
return 0;
}

OUTPUT
10.PROGRAM TO FIND THE SMALLEST NUMBER IN AN
ARRAY.
#include<stdio.h>
#include<conio.h>
int main()
{
int num[20],n,i,small;
clrscr();
printf("Enter the number of elements ");
scanf(" %d",&n);
printf("Enter the numbers ");
for(i=1;i<=n;i++)
{
scanf(" %d",&num[i]);
}
small=num[0];
for(i=1;i<=n;i++)
{
if(num[i]<small)
{
small=num[i];
}
}
printf("the smallest number is %d",small);
getch();
return 0;
}

OUTPUT.
11.LARGEST NUMBER IN AN ARRAY.
#include<stdio.h>
#include<conio.h>
int main()
{
int num[20],n,i,large;
clrscr();
printf("Enter the number of elements ");
scanf(" %d",&n);
printf("Enter the numbers ");
for(i=1;i<=n;i++)
{
scanf(" %d",&num[i]);
}
large=num[0];
for(i=1;i<=n;i++)
{
if(num[i]>large)
{
large=num[i];
}
}
printf("the largest number is %d",large);
getch();
return 0;
}
OUTPUT.
12.SET OF NUMBERS IN ACCENDING ORDER.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,j,num[25],temp;
clrscr();
printf("Enter the number of elements:");
scanf("%d",&n);
printf("enter the elements:");
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i]>num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("sorted array \n");
for(i=0;i<n;i++)
{
printf("%d\n",num[i]);
}
getch();
return 0;
}

OUTPUT
13.PROGRAM FOR SET OF NUMBERS IN DECENDING
ORDER.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,j,num[25],temp;
clrscr();
printf("Enter the number of elements:");
scanf("%d",&n);
printf("enter the elements:");
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i]<num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("sorted array \n");
for(i=0;i<n;i++)
{
printf("%d\n",num[i]);
}
getch();
return 0;
}

OUTPUT
14.PROGRAM FOR TEMPERATURE CONVERSION.
#include<stdio.h>
#include<conio.h>
int main()
{
float c,f;
int sel;
clrscr();
printf("Enter your selection either 1 or 2 \n");
printf("Select 1 to convert from celsius to fahrenheit \n");
printf("Select 2 to convert from fahrenheit to celsius \n");
scanf("%d",&sel);
if(sel==1)
{
printf("Enter temperature in celsius;");
scanf("%f",&c);
f=((c*9/5)+32);
printf("Temperature in fahrenheit is :%.2f",f);
}
else
{
printf("Enter temperature in fahrenheit:");
scanf("%f",&f);
c=((f-32)/1.8);
printf("Temperature in celsius is :%.2f",c);
}
getch();
return 0;
}

OUTPUT
15.PROGRAM FOR PRIME NUMBER GENERATION.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,j,flag=0;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
printf("prime numbers are:\n");
for(i=2;i<=n;i++)
{
flag=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
flag++;
}
}
if(flag==0)
{
printf("\n%d",i);
}
}
getch();
return 0;
}

OUTPUT.
16.PROGRAM FOR LINEAR SERCH.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,j,num[25],serch,flag=0;
clrscr();
printf("Enter the limit: " );
scanf("%d",&n);
printf("Enter the numbers: " );
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
printf("Enter the numbers to serch " );
scanf("%d",&serch);
for(i=0;i<n;i++)
{
if(serch==num[i])
{
printf("The number %d",num[i]);
printf("Present at location %d",i);
flag=1;
}
}
if(flag==0)
{
printf("The number not found ");
}
getch();
return 0;
}

OUTPUT.
17.PROGRAM FOR ADDITION OF TWO MATRICES.
#include<stdio.h>
#include<conio.h>
int main()
{
int A[10][10],B[10][10],C[10][10],i,j,k,v,m,n,p,q;
clrscr();
printf("Enter the order of matrix A ");
scanf("%d%d",&m,&n);
printf("Enter the order of matrix B ");
scanf("%d%d",&p,&q);
if(m==p&&n==q)
{
printf("Enter the elements to matrix A ");
for(i=0;i<m;i++)
for(j=0;j<m;j++)
scanf("%d",&A[i][j]);
printf("Enter the elements to matrix B ");
for(i=0;i<p;i++)
{
for(j=0;j<p;j++)
{
scanf("%d",&B[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ", C[i][j]);
}
printf("\n");
}
}
else
{
printf("Error:Entered matrices can`t be added ");
}
getch();
return 0;
}
OUTPUT.
18.PROGRAM FOR DIFFERENCE OF TWO MATRICES.
#include<stdio.h>
#include<conio.h>
int main()
{
int A[10][10],B[10][10],C[10][10],i,j,m,n,p,q;
clrscr();
printf("Enter the order of matrix A ");
scanf("%d%d",&m,&n);
printf("Enter the order of matrix B ");
scanf("%d%d",&p,&q);
if(m==p&&n==q)
{
printf("Enter the elements to matrix A ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&A[i][j]);
}
}
printf("Enter the elements to matrix B ");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&B[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
C[i][j]=A[i][j]-B[i][j];
}
}
printf("Difference of the matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",C[i][j]);
}
printf("\n");
}
}
else
{
printf("Error:Entered matrices canot be subtracted ");
}
getch();
return 0;
OUTPUT.
19.PROGRAM FOR MATRIX MULTIPLICATION.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,m,n,k,p,q,sum=0,A[5][5],B[5][5],product[10][10];
clrscr();
printf("Enter the order of matrix A:");
scanf("%d%d",&m,&n);
printf("Enter the order of matrix B:");
scanf("%d%d",&p,&q);
if(n==p)
{
printf("Enter the matrix A: ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&A[i][j]);
}
}
printf("Enter the matrix B:");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&B[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for(k=0;k<p;k++)
{
sum=sum+A[i][k]*B[k][j];
}
product[i][j]=sum;
sum=0;
}
}
printf("Product of matrix :\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d ",product[i][j]);
}
printf("\n");
}
}
else
{
printf("Error:Cannot be multiplied");
}
getch();
return 0;
}

OUTPUT.
20.PROGRAM FOR IDENTITY MATRIX.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,m,n,A[5][5],flag=1;
clrscr();
printf("Enter the order of matrix : ");
scanf("%d%d",&m,&n);
printf("Enter the matrix : ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&A[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(A[i][j]!=1&&A[j][i]!=0)
{
flag=0;
break;
}
}
}
if(flag==1)
{
printf("Identity matrix");
}
else
{
printf("Not an identity matrix");
}
getch();
return 0;
}

OUTPUT.
21.PROGRAM FOR TRANSPOSE OF A MATRIX.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,m,n,A[5][5],transpose[5][5];
clrscr();
printf("Enter the order of matrix: ");
scanf("%d%d",&m,&n);
printf("Enter the matrix ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&A[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
transpose[i][j]=A[j][i];
}
}
printf("Transpose of a matrix =\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",transpose[i][j]);
}
printf("\n");
}
getch();
return 0;
}

OUTPUT.
22.PROGRAM TO FIND NUMBER OF VOWELS IN A
STRING.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char a[25];
int count=0,i,l;
clrscr();
printf("Enter the string :");
gets(a);
l=strlen(a);
for(i=0;i<l;i++)
{

if(a[i]=='a'||a[i]=='A'||a[i]=='e'||a[i]=='E'||a[i]=='i'||a[i]=='I'||a[i]=='O'||a[i]=='
o'||a[i]=='U'||a[i]=='u')
{
count ++;
}
}
printf("Number of vowels=%d",count);
getch();
return 0;
}
OUTPUT.
23.PROGRAM TO COPY STRING FROM SOURCE
VARIABLE TO DESTINATION VARIABLE.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char s[20],d[20];
int i,l;
clrscr();
printf("Enter the string :");
gets (s);
l=strlen(s);
for(i=0;i<=l;i++)
{
d[i]=s[i];
}
printf("Copied string is :");
puts(d);
getch();
return 0;
}

OUTPUT.
24.PROGRAM TO FIND FACTORIAL OF A NUMBER.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int factorial (int n);
int main()
{
int z,num;
clrscr();
printf("Enter the number :");
scanf("%d",&num);
z=factorial(num);
printf("Factorial of %d is %d",num,z);
getch();
return 0;
}
int factorial (int n)
{
int fact;
if(n==0)

{
return 1;
}
else
fact=n*factorial(n-1);
return fact;
}

OUTPUT.
25.PROGRAM FOR CHECKING PALINDROME.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char a[30],b[30];
int i,l,j=0;
clrscr();
printf("Enter the string :");
gets(a);
l=strlen(a);
for(i=l-1;i>=0;i--)
{
b[j]=a[i];
j++;
}
b[j]='\0';
if(strcmp(a,b)==0)
{
printf("The string is palindrome");
}
else
{
printf("The string is not palindrome");
}
getch();
return 0;
}

OUTPUT.
26.PROGRAM FOR SWAPING BY CALL BY VALUE METHOD
#include<stdio.h>
#include<conio.h>
void swap (int a, int b);
int main()
{
int m=22,n=44;
clrscr();
printf("value of actual parameters before swap m=%d and n=%d\n",m,n);
swap(m,n);
printf("value of actual parameters after swap m=%d and n=%d",m,n);
getch();
return 0;
}
void swap(int a,int b)
{
int temp;
printf("Value of formal parameters before swap a=%d and b=%d\n",a,b);
temp=a;
a=b;
b=temp;
printf(".....................................................\n");
printf("value of formal parameters after swap a=%d and b=%d\n",a,b);
}
OUTPUT.
27.PROGRAM FOR SWAPPING BY CALL BY REFFERENCE METHOD
#include<stdio.h>
#include<conio.h>
void swap (int *a, int *b);
int main()
{
int m=22,n=44;
clrscr();
printf("value of actual parameters before swap m=%d and n=%d\n",m,n);
swap(&m,&n);
printf("value of actual parameters after swap m=%d and n=%d",m,n);
getch();
return 0;
}
void swap(int *a,int *b)
{
int temp;
printf("Value of formal parameters before swap a=%d and b=%d\n",*a,*b);
temp=*a;
*a=*b;
*b=temp;
printf(".....................................................\n");
printf("value of formal parameters after swap a=%d and b=%d\n",*a,*b);
}
OUTPUT.
28.PROGRAM TO FIND ROOT OF A QUADRATIC EQUATION.
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c,d,root1,root2,imaginary,real;
clrscr();
printf("Enter the coefficients a,b and c");
scanf("%f %f %f",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d>0)
{
root1=((-b+(sqrt(d)))/(2*a));
root2=((-b-(sqrt(d)))/(2*a));
printf("Roots are real and distinct\n");
printf("Root1=%.2f\n",root1);
printf("Root2=%.2f\n",root2);
}
else if(d<0)
{
imaginary=sqrt(-d)/2*a;
real=-b/2*a;
printf("Roots are imaginary\n");
printf("Root1=%.2f+i%.2f\n",real,imaginary);
printf("Root2=%.2f-i%.2f",real,imaginary);
}
else
{
root1=-b/(2*a);
printf("Roots are real and equal\n");
printf("Root1=%.2f",root1);
}
getch();
return 0;
}

OUTPUT.
29.PROGRAM FOR FINDING RADIUS AND CIRCUMFRENCE.
#include<stdio.h>
#include<conio.h>
int main()
{
int r;
float area,circum;
int *ptr;
clrscr();
printf("Enter the radius r= ");
scanf("%d",&r);
ptr=&r;
area=(3.14*((*ptr)*(*ptr)));
circum=(2*3.14*(*ptr));
printf("Area =%.2f\n",area);
printf("Circumfrence =%.2f\n",circum);
getch();
return 0;
}

OUTPUT.
30.PROGRAM FOR JOINING TWO STRINGS.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char s[10],d[10];
int i,j,l;
clrscr();
printf("Enter the 1st string:”);
gets(s);
printf(“Enter the 2nd string:”);
gets(d);
j=strlen(s);
for(i=0;d[i]!=’\0’;i++)
{
s[j]=d[i];
j++;
}
d[i]=’\0’;
printf(“Combined string:%s”,s);
getch();
return 0;
}
OUTPUT
31.STUDENT RECORD
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
int rollno;
int sub[3];
int total;
char name[25];
}st[10];
int main()
{
int i,j,n;
clrscr();
printf("Enter the number of students : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter roll no :");
scanf("%d",&st[i].rollno);
printf("Enter name :");
scanf("%s",st[i].name);
printf("Enter mark of 3 subjects :\n");
//st[i].total=0;
for(j=0;j<3;j++)
{
printf("Enter subject %d mark : ",j+1);
scanf("%d",&st[i].sub[j]);
st[i].total=st[i].total+st[i].sub[j];
/*printf("%d",st[i].total);*/
}
}
printf("\n* * * * Students Details * * * *\n");
printf("Rollno \tName subject1 subject2 subject3 Total\n");
for(i=0;i<n;i++)
{
printf(" %d\t\t\%s\t",st[i].rollno,st[i].name);
for(j=0;j<3;j++)
{
printf("\t%d",st[i].sub[j]);
}
printf("\t%d\n",st[i].total);
}
getch();
return 0;
}
OUTPUT.

You might also like