You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Program to find Area, Perieter, Volume of a Circle
Program to find Area, Perimeter of a Rectangle
Program to find Interest
Program to find Maximum
Program to find a Power of a Number
Program To find Minimum
Program to take 5 values from the user and store them in an array and Print the elements stored in the array
Program to use Arithmetic Operators
Program to use Assignment Operators
Program to use Operator Precedence
Program to find Average
Program to print Fibbonacci Series ( using Recursion )
Program to find FizzBuzz od a Integer
Program swap two numbers using call by value
Program swap two numbers using call by reference
Program of Addition of 2x2 Matrix
Program of Multiplication of 2x2 Matrix
Program of FizzBuzz in a continues loop
Program to find Sum by using function
Program to print a Pyramid
Program to implement Linear search for One Dimensional array
Program to implement linear search with desirable values
Program to implement Binary search with desirable values
Program to find Prime number
Program of days of the week
Program to print Even numbers using while loop
Program of Volume (Different Shapes)
Program to find Sum of A.P series
Program to multiply Two Floating Point Numbers
Program to find weather the Number is Even or Odd using if-else statement
Program to find Sum of First 10 Natural Numbers using for loop
Program to print Odd numbers using do while loop
Program of a Simple Calculator
Program to implement Bubble Sort
Program to find Factorial
Program to Store Information of a Student using Structure
Program to find Multiplication of Matrix using array
Program to Find Palindrome Number
Program to Implement Bubble Sort (using Recursion)
Program to Find Factorial (using Recursion)
Program to find Fibonacci series
Program to find roots of quadratic eqation
1. Program to find Sum
#include<stdio.h>intmain()
{
floatx,y,z;
printf("\nEnter The First Numder: ");
scanf("%f", &x);
printf("\nEnter The Second Numder: ");
scanf("%f", &y);
z=x+y;
printf("\nAnswer is: = %.3f", z);
return0;
}
Output of the program
Enter The First Numder: 45.26
Enter The Second Numder: 78.2648
Answer is: = 123.525
73.00 x 1 = 73.000
73.00 x 2 = 146.000
73.00 x 3 = 219.000
73.00 x 4 = 292.000
73.00 x 5 = 365.000
73.00 x 6 = 438.000
73.00 x 7 = 511.000
4. Program to find Area, Perieter, Volume of a Circle
#include<stdio.h>intmain()
{
floatr,P,A,V;
floatpi=22/7.0;
printf("\nEnter The Radius of Circle: ");
scanf("%f",&r);
P=2*pi*r;
A=pi*r*r;
V=4*pi*r*r*r/3.0;
printf("\nPerimeter of Circle is: = %.2f",P);
printf("\nArea of Circle is: = %.2f",A);
printf("\nVolume of Circle is: = %.2f",V);
return0;
}
Output of the program
Enter The Radius of Circle: 4.5
Perimeter of Circle is: = 28.29
Area of Circle is: = 63.64
Volume of Circle is: = 381.86
Enter Height: 24
Enter Bredth: 60
Area of Sqare (or) Rectangle: = 1440.000
Perimeter of Sqare (or) Rectangle: = 168.000
6. Program to find Interest
#include<stdio.h>intmain()
{
floatP,R,T,Interest;
printf("\nEnter The Principal Amount: ");
scanf("%f", &P);
printf("\nEnter The Interest Rate: ");
scanf("%f", &R);
printf("\nEnter The Time (in months): ");
scanf("%f", &T);
Interest=P*T*R/100;
printf("\nSimple Intesest is: = %.2f", Interest);
returnInterest;
}
Output of the program
Enter The Principal Amount: 4000
Enter The Interest Rate: 4
Enter The Time (in months): 3
Simple Intesest is: = 480.00
7. Program to find Maximum
#include<stdio.h>intmax(floatx,floaty);
intmain()
{
floatx,y,z;
printf("\nEnter The First Value: ");
scanf("%f",&x);
printf("\nEnter The Second Value: ");
scanf("%f",&y);
z=max(x,y);
printf("\nMaximum value is: %.2f\n", z);
return0;
}
intmax(floatx,floaty)
{
floatresult;
if(x<y)
result=y;
elseresult=x;
returnresult;
}
Output of the program
Enter The First Value: 5
Enter The Second Value: 4
Maximum value is: 5.00
8. Program to find a Power of a Number
#include<stdio.h>intmain()
{
intbase,power,ans=1;
printf("\nEnter base number: ");
scanf("%d",&base);
printf("Enter exponent(power): ");
scanf("%d",&power);
while (power!=0)
{ ans *= base;
power--; }
printf("Answer = %d\n", ans);
return0;
}
Output of the program
Enter base number: 5
Enter exponent(power): 4
Answer = 625
9. Program To find Minimum
#include<stdio.h>intmin(floatx,floaty);
intmain()
{
floatx,y,z;
printf("\nEnter The First Value: ");
scanf("%f",&x);
printf("\nEnter The SecondValue: ");
scanf("%f",&y);
z=min(x,y);
printf("\nMinimum value is: %.2f\n", z);
return0;
}
intmin(floatx,floaty)
{
floatresult;
if(x<y)
result=x;
elseresult=y;
returnresult;
}
Output of the program
Enter The First Value: 5
Enter The SecondValue: 3
Minimum value is: 3.00
10. Program to take 5 values from the user and store them in an array and Print the elements stored in the array
Enter [1] element: 4
Enter [2] element: 5
Enter [3] element: 6
Enter [4] element: 9
Enter [5] element: 2
Element [1] = 4
Element [2] = 5
Element [3] = 6
Element [4] = 9
Element [5] = 2
11. Program to use Arithmetic Operators
#include<stdio.h>intmain()
{
floatx,y,a;
printf("\nEnter The Value of x: ");
scanf("%f",&x);
printf("\nEnter The Value of y: ");
scanf("%f",&y);
a=x+y;
printf("x + y = %.3f\n",a);
a=x-y;
printf("x - y = %.3f\n",a);
a=y-x;
printf("y - x = %.3f\n",a);
a=x*y;
printf("x * y = %.3f\n",a);
a=x/y;
printf("x/y = %.3f\n",a);
a=y/x;
printf("y/x = %.3f\n",a);
return0;
}
Output of the program
Enter The Value of x: 45
Enter The Value of y: 31
x + y = 76.000
x - y = 14.000
y - x = -14.000
x * y = 1395.000
x/y = 1.452
y/x = 0.689
12. Program to use Assignment Operators
#include<stdio.h>intmain()
{
floatx,a;
printf("\nEnter The Value of x: ");
scanf("%f",&x);
a=x;
printf("Answer is a = x %.3f\n",a);
a+=x; //answer is a+xprintf("Answer is a+x = %.3f\n",a);
a-=x; //answer is a-xprintf("Answer is a-x = %.3f\n",a);
a *=x; //answer is a*xprintf("Answer is a*x = %.3f\n",a);
a /=x; //answer is a/xprintf("Answer is a/x= %.3f\n",a);
return0;
}
Output of the program
Enter The Value of x: 45
Answer is a = x 45.000
Answer is a+x = 90.000
Answer is a-x = 45.000
Answer is a*x = 2025.000
Answer is a/x= 45.000
13. Program to use Operator Precedence
#include<stdio.h>intmain()
{
floata,b,c,d,A;
printf("\nEnter 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);
printf("Enter The Value of d: ");
scanf("%f",&d);
A= (a+b)*(c+d);
printf("\n (a+b)*(c+d) = %.3f",A);
A= (c+d)*a*b;
printf("\n (c+d)*a*b = %.3f",A);
A=a*d/(c-b-a);
printf("\n a*d/(c-b-a) = %.3f",A);
A= (b-c)*(a-d);
printf("\n (b-c)*(a-d) = %.3f",A);
return0;
}
Output of the program
Enter The Value of a: 45
Enter The Value of b: 31
Enter The Value of c: 18
Enter The Value of d: 71
(a+b)*(c+d) = 6764.000
(c+d)*a*b = 124155.000
a*d/(c-b-a) = -55.086
(b-c)*(a-d) = -338.000
14. Program to find Average
#include<stdio.h>intmain()
{
intx,N;
floatavg[1000],s,ans;
printf("\nEnter the Number of elements: ");
scanf("%d", &N);
printf("\n");
for(x=1; x<=N; x++)
{ printf("Enter [%d] element: ", x);
scanf("%f", &avg[x]);
s+=avg[x]; }
ans=s/N;
printf("\nAverage of %d elements = %.3f", N, ans);
return0;
}
Output of the program
Enter the Number of elements: 8
Enter [1] element: 1
Enter [2] element: 2
Enter [3] element: 3
Enter [4] element: 4
Enter [5] element: 5
Enter [6] element: 6
Enter [7] element: 7
Enter [8] element: 8
Average of 8 elements = 4.500
15. Program to print Fibbonacci Series ( using Recursion )
Enter the two integers: 45 98
Before Swapping
x = 45
y = 98
After Swapping
x = 98
y = 45
19. Program of Addition of 2x2 Matrix
#include<stdio.h>intmain()
{
floata,b,c,d,e,f,g,h,i,j,k,l;
printf("\nSample of Ist matrix: | a=1 b=2 |\n | c=3 d=4 |\n\n\ Sample of 2nd matrix: | e=5 f=6 |\n | f=7 h=8 |\n\n");
printf("Enter The Valve of a: ");
scanf("%f",&a);
printf("Enter The Valve of b: ");
scanf("%f",&b);
printf("Enter The Valve of c: ");
scanf("%f",&c);
printf("Enter The Valve of d: ");
scanf("%f",&d);
printf("Enter The Valve of e: ");
scanf("%f",&e);
printf("Enter The Valve of f: ");
scanf("%f",&f);
printf("Enter The Valve of g: ");
scanf("%f",&g);
printf("Enter The Valve of h: ");
scanf("%f",&h);
i=a+e;
j=b+f;
k=c+g;
l=d+h;
printf("\n\nSum of Matrix(A+B) is: | %.2f %.2f |\n | %.2f %.2f |",i,j,k,l);
i=a-e;
j=b-f;
k=c-g;
l=d-h;
printf("\n\nSubstraction of Matrix(A-B) is: | %.2f %.2f |\n | %.2f %.2f |",i,j,k,l);
i=e-a;
j=f-b;
k=g-c;
l=h-d;
printf("\n\nSubstraction of Matrix(B-A) is: | %.2f %.2f |\n | %.2f %.2f |",i,j,k,l);
return0;
}
Output of the program
Sample of Ist matrix: | a=1 b=2 |
| c=3 d=4 |
Sample of 2nd matrix: | e=5 f=6 |
| f=7 h=8 |
Enter The Valve of a: 7
Enter The Valve of b: 5
Enter The Valve of c: 4
Enter The Valve of d: 0
Enter The Valve of e: 3
Enter The Valve of f: 5
Enter The Valve of g: 9
Enter The Valve of h: 1
Sum of Matrix(A+B) is: | 10.00 10.00 |
| 13.00 1.00 |
Substraction of Matrix(A-B) is: | 4.00 0.00 |
| -5.00 -1.00 |
Substraction of Matrix(B-A) is: | -4.00 0.00 |
| 5.00 1.00 |
20. Program of Multiplication of 2x2 Matrix
#include<stdio.h>intmain()
{
floata,b,c,d,e,f,g,h,i,j,k,l;
printf("\nSample of Ist matrix: | a=1 b=2 |\n | c=3 d=4 |\n\n\ Sample of 2nd matrix: | e=5 f=6 |\n | f=7 h=8 |\n\n");
printf("Enter The Valve of a: ");
scanf("%f",&a);
printf("Enter The Valve of b: ");
scanf("%f",&b);
printf("Enter The Valve of c: ");
scanf("%f",&c);
printf("Enter The Valve of d: ");
scanf("%f",&d);
printf("Enter The Valve of e: ");
scanf("%f",&e);
printf("Enter The Valve of f: ");
scanf("%f",&f);
printf("Enter The Valve of g: ");
scanf("%f",&g);
printf("Enter The Valve of h: ");
scanf("%f",&h);
i=(a*e)+(b*g);
j=(a*f)+(b*h);
k=(c*e)+(d*g);
l=(c*f)+(d*h);
printf("\nMultiplication of A,B is: | %.2f %.2f |\n | %.2f %.2f |",i,j,k,l);
return0;
}
Output of the program
Sample of Ist matrix: | a=1 b=2 |
| c=3 d=4 |
Sample of 2nd matrix: | e=5 f=6 |
| f=7 h=8 |
Enter The Valve of a: 7
Enter The Valve of b: 5
Enter The Valve of c: 4
Enter The Valve of d: 0
Enter The Valve of e: 3
Enter The Valve of f: 5
Enter The Valve of g: 9
Enter The Valve of h: 1
Multiplication of A,B is: | 66.00 40.00 |
| 12.00 20.00 |
#include<stdio.h>intans(floata, floatb);
intmain()
{
floata, b, ans;
printf("\nEnter The Value of a: ");
scanf("%f",&a);
printf("Enter The Value of b: ");
scanf("%f",&b);
ans= (a*b);
printf("Answer is: %.2f", ans);
return0;
}
intans(floata, floatb)
{
returna*b;
}
Output of the program
Enter The Value of a: 4
Enter The Value of b: 5
Answer is: 20.00
Enter number of Rows: 6
*
***
*****
*******
*********
***********
24. Program to implement Linear search for One Dimensional array
#include<stdio.h>intmain()
{
intarray[12]={1,5,9,7,3,82,46,23,23,5,10,3};
intsize=12,flag=0,item,a;
printf("\nEnter the Value to be Searched: ");
scanf("%d", &a);
for(inti=0;i<size;i++)
{
if(a==array[i])
{
flag=a;
break;
}
}
if(flag==a)
printf("\nSearch is Sucessfull \n%d Element is present in the array\n",a);
elseprintf("\nSearch is Unsucessfull \n%d Element is not present in the array\n",a);
return0;
}
Output of the program
First Case
Enter the Value to be searched: 5
Search is Sucessfull 5 Element is present in the array
Second Case
Enter the Value to be searched: 2
Search is Unsucessfull 2 Element is not present in the array
25. Program to implement linear search with desirable values
#include<stdio.h>intmain()
{
intarray[100],search,i,n;
printf("\nEnter the Number of elements in array: ");
scanf("%d",&n);
printf("\n");
for(i=1;i<=n;i++)
{ printf("Enter [%d] element: ",i);
scanf("%d",&array[i]); }
printf("\nEnter a number to search: ");
scanf("%d",&search);
for(i=0;i<=n;i++)
{
if(array[i]==search) //if element is found
{ printf("\n%d is present at location %d\n",search,i);
break; }
elseif(i>=n)
{ printf("\n%d is not present in the array\n",search); }
}
return0;
}
Output of the Program
Enter the Number of elements in array: 5
Enter [1] element: 1
Enter [2] element: 2
Enter [3] element: 3
Enter [4] element: 4
Enter [5] element: 5
Enter a number to search: 8
8 is not present in the array
26. Program to implement Binary search with desirable values
#include<stdio.h>intmain()
{
intn,i,s,f,m,l,a[100]; //a= array, n= size of array, s= element to be searched//f= first element position, l= last element position//m= mid element positionprintf("\nEnter the size of array: ");
scanf("%d",&n);
printf("\n");
for(i=1;i<=n;i++)
{ printf("Enter [%d] element: ",i);
scanf("%d",&a[i]); }
printf("\nEnter the element you wants to search: ");
scanf("%d",&s);
f=0;
l=n-1;
m=(f+l)/2;
while(f<=l)
{
if (a[m]<s)
{ f=m+1; }
elseif(a[m]==s)
{ printf("Location of given %d is %d \n",s,m);
break; }
else
{ l=m-1; }
m=(f+l)/2;
}
if(f>l)
printf("%d is not found in the array\n",s);
return0;
}
output of the Program
Enter the size of array: 7
Enter [1] element: 5
Enter [2] element: 2
Enter [3] element: 8
Enter [4] element: 49
Enter [5] element: 657
Enter [6] element: 32
Enter [7] element: 0
Enter the element you wants to search: 5
Location of given 5 is 1
27. Program to find Prime number
#include<stdio.h>intmain()
{
inta,flag=0;
printf("\nEnter the Number: ");
scanf("%d",&a);
for(intx=2; x<a; x++)
{ if(a%x==0)
{ flag=1;
break; }
}
if(flag==1)
printf("%d is not a Prime Number",a);
if(flag==0)
printf("%d is a Prime Number",a);
return0;
}
Output of the program
Enter the Number: 7
7 is a Prime Number
Enter the Number: 8
8 is not a Prime Number
#include<stdio.h>intmain()
{
inta; //a = Code of the shape floatsphere,Sr,pi=22.0/7.0; //Cr = radius of circle, sphere = volume (Sphere)floatCs,cube; //Cs = side, cude = volumre (cube)floatRl,Rb,Rh,rectangle; //Rl = length, Rb = breadth, Rh = Heigth, rectangle = volume (Rectangle)floatCr,Ch,cylinder; //Cr = Radius, Ch = Height, cylinder = Volume (cylinder)floatCoR,CoH,cone; //CoR = Radius, CoH = Height, cone = Volume (Cone)printf("\n\nPress 1 (Sphere) \nPress 2 (Cube) \nPress 3 (Rectangle) \n\ Press 4 (Cylinder) \nPress 5 (Cone) \n\nEnter the shape,you wants to find the volume: ");
scanf("%d", &a);
switch(a)
{
case1:
if(a==1)
{ printf("\nEnter the radius of Sphere: ");
scanf("%f", &Sr);
sphere=4*pi*Sr*Sr*Sr/3;
printf("Volume of Shpere = %.4f", sphere);
break; }
case2:
if(a==2)
{ printf("\nEnter the Side of Cube: ");
scanf("%f", &Cs);
cube=Cs*Cs*Cs;
printf("Volume of Cube = %.4f", cube);
break; }
case3:
if(a==3)
{ printf("\nEnter the length of Rectangle: ");
scanf("%f", &Rl);
printf("Enter the breadth of Rectangle: ");
scanf("%f", &Rb);
printf("Enter the Height of Rectangle: ");
scanf("%f", &Rh);
rectangle=Rl*Rb*Rh;
printf("Volume of Rectangle = %.4f", rectangle);
break; }
case4:
if(a==4)
{ printf("\nEnter the Radius of Cylinder: ");
scanf("%f", &Cr);
printf("Enter the Height of Cylinder: ");
scanf("%f", &Ch);
cylinder=pi*Cr*Cr*Ch;
printf("Volume of Cylinder = %.4f", cylinder);
break; }
case5:
if(a==5)
{ printf("\nEnter the Radius of Cone: ");
scanf("%f", &CoR);
printf("Enter the Height of Cone: ");
scanf("%f", &CoH);
cone=pi*CoR*CoR*CoH/3;
printf("Volume of Cone = %.4f", cone);
break; }
}
return0;
}
output of the Program
Press 1 (Sphere)
Press 2 (Cube)
Press 3 (Rectangle)
Press 4 (Cylinder)
Press 5 (Cone)
Enter the shape,you wants to find the volume: 1
Enter the radius of Sphere: 10
Volume of Shpere = 4190.4761
Enter the shape,you wants to find the volume: 2
Enter the Side of Cube: 17.5
Volume of Cube = 5359.3750
Enter the shape,you wants to find the volume: 3
Enter the length of Rectangle: 11
Enter the breadth of Rectangle: 12
Enter the Height of Rectangle: 13
Volume of Rectangle = 1716.0000
Enter the shape,you wants to find the volume: 4
Enter the Radius of Cylinder: 7
Enter the Height of Cylinder: 8
Volume of Cylinder = 1232.0000
Enter the shape,you wants to find the volume: 5
Enter the Radius of Cone: 2
Enter the Height of Cone: 1.5
Volume of Cone = 6.2857
31. Program to find Sum of A.P series
#include<stdio.h>intmain()
{
intN,x; //N = length of the series, x = second term or differencefloata1,a2,d,S; //a1 = first or last term//a2 = second term, d = differenc//S = sum of the termsprintf("\n\nEnter N of the series: ");
scanf("%d", &N);
printf("Enter first or last term of the series: ");
scanf("%f", &a1);
printf("\nEnter 1 for Second term, Enter 2 for difference\n\nEnter 1 or 2: ");
scanf("%d", &x);
if(x==1)
{ printf("\nEnter the second term: ");
scanf("%f", &a2);
d=a2-a1;
S=N*(2*a1+ (N-1)*d) /2;
printf("\nSum of given series = %.2f", S); }
elseif(x==2)
{ printf("\nEnter the Difference: ");
scanf("%f", &d);
S=N*(2*a1+ (N-1)*d) /2;
printf("\nSum of given series = %.2f", S); }
elseprintf("\nEnter a valid input(1 or 2)");
return0;
}
Output of the Program
Enter N of the series: 10
Enter first or last term of the series: 2
Enter 1 for Second term, Enter 2 for difference
Enter 1 or 2: 1
Enter the second term: 6
Sum of given series = 200.00
32. Program to multiply Two Floating Point Numbers
#include<stdio.h>intmain()
{
floatx,y,ans;
printf("\n\nEnter the First value: ");
scanf("%f", &x);
printf("Enter the Second value: ");
scanf("%f", &y);
ans=x*y;
printf("\nAnswer = %.3f",ans);
return0;
}
Output of the Program
Enter the First value: 1.2
Enter the Second value: 3.2
Answer = 3.840
33. Program to find weather the Number is Even or Odd using if-else statement
#include<stdio.h>intmain()
{
intx;
printf("\n\nEnter the Number: ");
scanf("%d", &x);
if(x%2==0)
printf("%d is Even", x);
elseprintf("%d is Odd", x);
return0;
}
Output of the Program
Enter the Number: 6
6 is Even
Enter the Number: 9
9 is Odd
34. Program to find Sum of First 10 Natural Numbers using for loop
#include<stdio.h>intmain()
{
intx,ans;
for(x=1;x<=10;x++)
{ ans+=x; }
printf("\n\nSum of first 10 Nmubers: %d",ans);
return0;
}
Output of the Program
Sum of first 10 Nmubers: 55
35. Program to print Odd numbers using do while loop
#include<stdio.h>intmain()
{
intx=1,N;
printf("\n\nEntere the Integer: ");
scanf("%d", &N);
do
{
if(x%2!=0)
printf("\n%d", x);
elseprintf("");
x++;
}
while(x<=N);
return0;
}
Output of the Program
Entere the Integer: 13
1
3
5
7
9
11
13
36. Program of a Simple Calculator
include<stdio.h>intmain()
{
charoperator;
floatx,y;
printf("\n\nEnter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%f %f", &x, &y);
switch(operator)
{
case'+':
printf("\n%.2f + %.2f = %.2f", x, y, x+y);
break;
case'-':
printf("\n%.2f - %.2f = %.2f", x, y, x-y);
break;
case'*':
printf("\n%.2f * %.2f = %.2f", x, y, x*y);
break;
case'/':
printf("\n%.2f / %.2f = %.2f", x, y, x/y);
break;
default:
printf("\nError! operator is not correct");
}
return0;
}
Output of the Program
Enter an operator (+, -, *, /): *
Enter two operands: 146 21
146.00 * 21.00 = 3066.00
37. Program to implement Bubble Sort
#include<stdio.h>intmain()
{
intarray[100], n, c, d, swap;
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c=0; c<n; c++)
scanf("%d", &array[c]);
for (c=0; c<n-1; c++)
{
for (d=0 ; d<n-c-1; d++)
{
if (array[d] >array[d+1])
{
swap=array[d];
array[d] =array[d+1];
array[d+1] =swap;
}
}
}
printf("Sorted list in ascending order:\n");
for (c=0; c<n; c++)
printf("%d\n", array[c]);
return0;
}
Output of the Program
Enter number of elements: 6
Enter 6 integers
1
2
3
8
9
1
Sorted list in ascending order:
1
1
2
3
8
9
38. Program to find Factorial
#include<stdio.h>longfactorial(int);
intmain()
{ intx;
longfact=1;
printf("\nEnter a number to calculate it's factorial: ");
scanf("%d", &x);
printf("%d! = %ld\n", x, factorial(x));
return0; }
longfactorial(intx)
{ intc;
longans=1;
for (c=x; c>1; c--)
{ ans *= c; }
returnans;
}
Output of the Program
Enter a number to calculate it's factorial: 6
6! = 720
Enter a number to calculate it's factorial: 12
12! = 479001600
39. Program to Store Information of a Student using Structure
#include<stdio.h>structstudent
{ charname[50];
long intph,marks; };
intmain()
{
printf("\nEnter the information of student: \n");
structstudents;
printf("Enter Name: ");
scanf("%s", &s.name);
printf("Enter Phone Number: ");
scanf("%ld", &s.ph);
printf("Enter Marks: ");
scanf("%d", &s.marks);
printf("\nEntered Information is: \n");
printf("Name: %s\n", s.name);
printf("Age: %ld\n", s.ph);
printf("Marks: %d\n", s.marks);
return0;
}
Output of the Program
Enter the information of student:
Enter Name: Sharanjit
Enter Phone Number: 9465329287
Enter Marks: 86
Entered Information is:
Name: Sharanjit
Age: 9465329287
Marks: 86
40. Program to find Multiplication of Matrix using array
#include<stdio.h>intmain()
{
inta[10][10], b[10][10], result[10][10], r1, c1, r2, c2, i, j, k;
// a and b are 1st and 2nd matrix// r1 and c1 is rows and column of 1st matrix respectively// r2 and c2 is rows and column of 2nt matrix respectively// result[10][10] is the multiplication of matrix 1 and 2// Geting the value of rows and columnsprintf("\nEnter rows and column for first matrix: ");
scanf("%d %d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d %d", &r2, &c2);
// Column of first matrix should be equal to column of second matrixwhile (c1!=r2)
{
printf("Error! Column of First Matrix is not equal to Row of Second Matrix.\n\n");
printf("Enter Rows and Column for First Matrix: ");
scanf("%d %d", &r1, &c1);
printf("Enter Rows and Column for Second Matrix: ");
scanf("%d %d", &r2, &c2);
}
// Storing elements of second matrix.printf("\nEnter elements of matrix 2:\n");
for(i=0; i<r2; ++i)
for(j=0; j<c2; ++j)
{
printf("Enter elements b[%d][%d]: ",i+1, j+1);
scanf("%d", &b[i][j]);
}
// Initializing all elements of result matrix to 0for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
{
result[i][j] =0;
}
// Multiplying matrices a and b and storing result in result matrixfor(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
for(k=0; k<c1; ++k)
{
result[i][j] +=a[i][k] *b[k][j];
}
// Displaying the resultprintf("\nOutput Matrix:\n");
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
{
printf("%d ", result[i][j]);
if(j==c2-1)
printf("\n\n");
}
return0;
}
Output of the Program
Enter rows and column for first matrix: 2 2
Enter rows and column for second matrix: 2 2
Enter elements of matrix 1:
Enter elements a[1][1]: 2
Enter elements a[1][2]: 3
Enter elements a[2][1]: 4
Enter elements a[2][2]: 5
Enter elements of matrix 2:
Enter elements b[1][1]: 9
Enter elements b[1][2]: 8
Enter elements b[2][1]: 1
Enter elements b[2][2]: 2
Output Matrix:
21 22
41 42
41. Program to Find Palindrome Number
#include<stdio.h>intmain()
{
intn, reverse=0, temp;
printf("Enter a number to check if it is a palindrome or not\n");
scanf("%d",&n);
temp=n;
while( temp!=0 )
{
reverse=reverse*10;
reverse=reverse+temp%10;
temp=temp/10;
}
if ( n==reverse )
printf("%d is a palindrome number.\n", n);
elseprintf("%d is not a palindrome number.\n", n);
return0;
}
Output
Enter a number to check if it is a palindrome or not
12321
12321 is a palindrome number
42. Program to Implement Bubble Sort (using Recursion)