0% found this document useful (0 votes)
18 views

All Basic Program of C

Uploaded by

Gaurav Dusane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

All Basic Program of C

Uploaded by

Gaurav Dusane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 97

Name :- Mayur Sharad Bonde

Department :- Applied Science Class :- F.E


Subject:- PPS ( PPS Practical )

Constant And Variables


1) Write a program for Addition by Arithmetic Operations.
#include<stdio.h>
void main()
{
int a,b,c;
printf(“enter the a and b--”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“the addition of a and b is - %d”,c);
}
Output :-
Enter the A and B--5 5
The addition of A and B is - 10

1
2) Write a program for Addition, Subtraction, Multiplication, Division
By Arithmetic Operations.
#include<stdio.h>
void main()
{
int a,b,c;
printf(“enter the a and b - ”);
scanf(“%d%d”,&a,&b);

c=a+b;
printf(“the addition of a and b is %d\n”,c);
c=a-b;
printf(“the subtraction of a and b is %d\n”,c);
c=a*b;
printf(“the multiplication of a and b is %d\n”,c);
c=a/b;
printf(“the division of a and b is %d\n”,c);
}
Output :-
Enter the A and B - 6 2
The addition of A and B is 8.000000
The Subtraction of A and B is 4.000000
The Multiplication of A and B is 12.000000
The Division of A and B is 3.000000

2
3) Write a program to calculate for simple interest.
#include<stdio.h>
void main()
{
float p,r,t,si;
printf(“enter the principal,rate and time-“);
scanf(“%f%f%f”,&p,&r,&t);
si=p*r*t*0.01;
printf(“the simple interest is--%f\n\n”,si);
}
Output :-
Enter the Principal,Rate and Time-
2000 4 5
The Simple Interest is—400.000000

3
4) Write a program for calculate area of rectangle.
#include<stdio.h>
void main()
{
int l,b,area;
printf("Enter the length and breadth--\n");
scanf("%d%d",&l,&b);
area=l*b;
printf("The area of Rectangle is--%d\n",area);
}
Output:-
Enter the length and breadth—5 4
The area of Rectangle is—20

4
5) Write a program for calculate area of triangle.
#include<stdio.h>
void main()
{
float l,b,area;
printf(“Enter The Length And Breadth--\n”);
scanf(“%f%f”,&l,&b);
area=0.5*l*b;
printf(“The Area Of Triangle Is--%f\n”,area);
}
Output:-
Enter The Length And Breadth— 3 5
The Area Of Triangle Is—7.500000

5
6) Write a program for calculate area of circle.
#include<stdio.h>
void main()
{
float r,area;
printf(“enter the radius of circle”);
scanf(“%f”,&r);
area=3.14*r*r;
printf(“the area of circle is--%f\n”,area);
}
Output:-
Enter the Radius of Circle6
The area of Circle is—113.040001

6
7) Write a program to convert temp.in degree Celsius to fahrenheit
#include<stdio.h>
void main()
{
float c,a;
printf(“convert degree celsius to fahrenheit\n”);
printf(“enter the celsius –“);
scanf(“%f”,&c);
a=(1.8*c)+32;
printf(“the fahrenheit is--%f\n”,a);
}
Output :-
Convert Degree Celsius to Fahrenheit
Enter the Celsius –24
The Fahrenheit is—75.199997

7
8) Write a program to calculate avg. Marks in 4 subjects.
#include<stdio.h>
void main()
{
float m1,pps,phy,beee,avg,total;
printf(“enter the m1 marks”);
scanf(“%f”,&m1);
printf(“enter the pps marks”);
scanf(“%f”,&pps);
printf(“enter the phy marks”);
scanf(“%f”,&phy);
printf(“enter the beee marks”);
scanf(“%f”,&beee);
total=m1+pps+phy+beee;
avg=total/4;
printf(“the subject average is - %f”,avg);
}
Output :-
Enter the M1 Marks40
Enter the PPS Marks50
Enter the Phy Marks60
Enter the BEEE Marks70
The Subject Average is – 55.000000

8
9) Write a program to calculate the percentage in 4 sub.
#include<stdio.h>
void main()
{
float m1,pps,phy,beee,per,total;
printf(“enter the m1 marks”);
scanf(“%f”,&m1);
printf(“enter the pps marks”);
scanf(“%f”,&pps);
printf(“enter the phy marks”);
scanf(“%f”,&phy);
printf(“enter the beee marks”);
scanf(“%f”,&beee);
total=m1+pps+phy+beee;
per=(total/400)*100;
printf(“the percentage is--%f percentage”,per);
}
Output :-
Enter the M1 Marks50
Enter the PPS Marks60
Enter the Phy Marks70
Enter the BEEE Marks80
The Percentage is—65.000000 Percentage

9
Control Statements

10) Write a program to find number is odd or even.


#include<stdio.h>
void main()
{
int n;
printf(“enter the number”);
scanf(“%d”,&n);
if(n%2==0)
{
printf(“number is even”);
}
else
{
printf(“number is odd”);
}
}
Output :-
Enter the number 5
Number is Odd

10
11) Write a program to find number is negative or positive.
#include<stdio.h>
void main()
{
int n;
printf(“enter the number –“);
scanf(“%d”,&n);
if(0<n)
{
printf(“\nnumber is positive”);
}
else
{
printf(“\nnumber is negative”);
}
}
Output :-Enter the number –8
Number is Positive

11
12) Write a program to find year is leap or not.
#include<stdio.h>
void main()
{
int year;
printf("Enter the number --");
scanf("%d",&year);
if(year%4==0)
{
printf("\nYear is leap year");
}
else
{
printf("\nNot leap Year");
}
}
Output :-
Enter the number –2024
Year is leap year

12
13) Write a program to find which number is greater in two Numbers.
#include<stdio.h>
void main()
{
int a,b;
printf(“enter the two number—“);
scanf(“%d%d”,&a,&b);
if(a>b)
{
printf(“\ngreter number is-%d”,a);
}
else
{
printf(“\ngreter number is-%d”,b);
}
}
Output :-
Enter the two number—34 32
Greter Number is-34

13
14) Write a program to find number is divisible or not.
#include<stdio.h>
void main()
{
int n1,n2;
printf(“enter number-“);
scanf(“%d”,&n1);
printf(“enter the no you want to divide-“);
scanf(“%d”,&n2);
if(n1%n2==0)
{
printf(“%d is the divisible by %d”,n1,n2);
}
else
{
printf(“%d is not divisible”,n2);
}
}
Output. :-
Enter Number-35
Enter the no you want to divide-8
8 is not divisible

14
15) Write a program to find which number is greater in three numbers
By using nested if else.
#include<stdio.h>
void main()
{
int a,b,c;
printf(“enter three number”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf(“greater number is %d”,a);
}
else
{
printf(“greater number is %d”,c);
}
}
else
if(b>c)
{
printf(“greater number is %d”,b);
}
else
{
printf(“greater number is %d”,c);
}
}
Output:-
Enter Three Number 39 28 45
Greater Number is 45

15
16) Write a program to determine you are pass or fail.
#include<stdio.h>
void main()
{
int n;
printf(“enter your marks-“);
scanf(“%d”,&n);
if(n>=35)
{
printf(“you are pass in exam”);
}
else
{
printf(“you are fail”);
}
}
Output :-
Enter your Marks-56
You are pass in exam

16
Switch Case
17) Write a program for Addition, Subtraction, Multiplication, Division
By Arithmetic Operations in switch case.
#include<stdio.h>
void main()
{ int n;
float sum,div,mul,sub,a,b;
printf(“1.addition\n2.division\n3.multiplication\n4.subtraction\n\n”);
printf(“enter the case no—“);
scanf(“%d”,&n);
switch (n)
{
case 1:
printf(“for addition enter the a and b”);
scanf(“%f%f”,&a,&b);
sum=a+b;
printf(“the addition is--%f”,sum);
break;
case 2:
printf(“for division enter the a and b”);
scanf(“%f%f”,&a,&b);
div=a/b;
printf(“the division is--%f”,div);
break;
case 3:
printf(“for multiplication enter the a and b”);
scanf(“%f%f”,&a,&b);
mul=a*b;
printf(“the multiplication is--%f”,mul);
break;
case 4:

17
printf(“for subtraction enter the a and b”);
scanf(“%f%f”,&a,&b);
sub=a-b;
printf(“the subtraction is--%f\n”,sub);
break;
default:
printf(“sorry,choose corrct case number..”);
}
}
Output. :-
1.Addition
2.Division
3.multiplication
4.subtraction
Enter the Case No—1
For Addition Enter the A and B6 9
The addition is—15.00000

18
18) Write a program to print the days from Sunday to Saturday by
Switch case
#include<stdio.h>
void main()
{
int n;
printf(“enter any number of 1 to 7—“);
scanf(“%d”,&n);
switch(n)
{
case 1:
printf(“—sunday”);
break;

case 2:
printf(“—monday”);
break;

case 3:
printf(“—tuesday”);
break;

case 4:
printf(“—wednesday”);
break;

case 5:
printf(“—thursday”);
break;

case 6:
printf(“—friday”);
break;

19
case 7:
printf(“—saturday”);
break;
default:
printf(“wrong choice”);
}
}
Output. :-
Enter any Number of 1 to 7—7
--Saturday

20
19) Write a program to find area of circle, area of rectangle, area of
Triangle, area of square by switch case.
#include<stdio.h>
void main()
{
int n;
float a,r,l,b;
printf(“\n1.area of circle\n2.area of rectangle\n3.area of
triangle\n4.area of square\n\n”);
printf(“enter the case value”);
scanf(“%d”,&n);

switch(n)
{
case 1:
printf(“enter the radius of circle”);
scanf(“%f”,&r);
a=3.14*r*r;
printf(“the area of cicle is%f”,a);
break;
case 2:
printf(“enter the length and breadth ”);
scanf(“%f%f”,&l,&b);
a=l*b;
printf(“the area of rectangle is%f”,a);
break;
case 3:
printf(“enter the length and breadth”);
scanf(“%f%f”,&l,&b);
a=0.5*l*b;
printf(“the area of triangle is%f”,a);
break;
case 4:

21
printf(“enter the length”);
scanf(“%f”,&l);
a=l*l;
printf(“the area of square is%f”,a);
break;
default :
printf(“\n\n\nsorry—select correct option....\n\n\n”);
}
}
Output :-
1.Area of Circle
2.Area of Rectangle
3.Area of Triangle
4.Area of square

Enter the case value 4


Enter the Length 3
The area of Square is9.000000

22
While Loop
20) Write a program to calculate sum of first n natural no.
#include<stdio.h>
void main()
{
int n,i=0,sum=0;
printf(“enter an integer-“);
scanf(“%d”,&n);
while(i<=n)
{
sum=sum+i;
i++;
}
printf(“the addition is--%d”,sum);
}
Output :-
Enter an Integer-5
The Addition is—15

23
21) Write a program to find factorial of number.
#include<stdio.h>
void main()
{
int n,i=1,fact=1;
printf(“enter an integer-“);
scanf(“%d”,&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf(“the addition is--%d”,fact);
}
Output. :-
Enter an Integer-5
The Addition is—120

24
22) Write a program to print 1 to 10
#include<stdio.h>
void main()
{
int n,i=1;
printf(“enter an integer-“);
scanf(“%d”,&n);
while(i<=n)
{
printf(“\n%d”,i);
i++;
}
}
Output :-
Enter an Integer-10
1
2
3
4
5
6
7
8
9
10

25
23) Write a program of table of n
#include<stdio.h>
void main()
{
int n,a,i;
printf(“enter the integer-“);
scanf(“%d”,&n);
i=1;
while(i<=n)
{
printf(“\n”);
a=1;
while(a<=10)
{
printf(“\n%d*%d=%d”,i,a,i*a);
a++;
}
i++;
}
}
Output. :-
Enter the integer-1
1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
1*6=6
1*7=7
1*8=8
1*9=9
1*10=10

26
24) Write a program to write a table of any number.
#include<stdio.h>
void main()
{
int i,n;
printf(“Enter an integer—“);
scanf(“%d”,&n);
i=1;
while (i<=10)
{
printf(“%d×%d=%d\n”,n,i,n*i);
i++;
}
}
Output. :-
Enter an integer—5
5×1=5
5×2=10
5×3=15
5×4=20
5×5=25
5×6=30
5×7=35
5×8=40
5×9=45
5×10=50

27
Do While
25) Write a program to calculate sum of first n natural .
#include<stdio.h>
void main()
{
int n,i=0,sum=0;
printf(“enter an integer-“);
scanf(“%d”,&n);
do
{
sum=sum+i;
i++;
}while(i<=n);
printf(“the addition is--%d”,sum);
}
Output :-
Enter an Integer-5
The Addition is—15

28
26) Write a program to find factorial of number.
#include<stdio.h>
void main()
{
int n,i=1,fact=1;
printf(“Enter an Integer-“);
scanf(“%d”,&n);
do
{
fact=fact*i;
i++;
}while(i<=n);
printf(“The Addition is--%d”,fact);
}
Output :-
Enter an Integer-4
The Addition is—24

29
27) Write a program to print 1 to 10.
#include<stdio.h>
void main()
{
int n,i=1;
printf(“Enter an Integer-“);
scanf(“%d”,&n);
do
{
printf(“\n%d”,i);
i++;
}while(i<=n);
}
Output :-
Enter an Integer-10

1
2
3
4
5
6
7
8
9
10

30
28) Write a program of table of n.
#include<stdio.h>
void main()
{
int n,a,i;
printf(“enter the integer-“);
scanf(“%d”,&n);
i=1;
do
{
printf(“\n”);
a=1;
do
{
printf(“\n%d*%d=%d”,i,a,i*a);
a++;
}while(a<=10);
i++;
}while(i<=n);
}
Output :-
Enter the integer-2

1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
1*6=6
1*7=7
1*8=8
1*9=9

31
1*10=10

2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
2*6=12
2*7=14
2*8=16
2*9=18
2*10=20

32
29) write a program to write a table of any number.
#include<stdio.h>
void main()
{
int i,n;
printf(“enter an integer—“);
scanf(“%d”,&n);
i=1;
do
{
printf(“%d×%d=%d\n”,n,i,n*i);
i++;
}while(i<=10);
}
Output :-
Enter an integer—5
5×1=5
5×2=10
5×3=15
5×4=20
5×5=25
5×6=30
5×7=35
5×8=40
5×9=45
5×10=50

33
For Loop
30) Write a program to calculate sum of first n natural no.
#include<stdio.h>
void main()
{
int n,i,sum=0;
printf("Enter an Integer-");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
sum=sum+i;
}
printf("The Addition is--%d",sum);
}
Output :-
Enter an Integer-5
The Addition is--15

34
31) Write a program to find factorial of number.
#include<stdio.h>
void main()
{
int n,i,fact=1;
printf(“enter an integer-“);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf(“the addition is--%d”,fact);
}
Output :-
Enter an Integer-5
The Addition is—120

35
32) Write a program to print 1 to 10.
#include<stdio.h>
void main()
{
int n,i;
printf(“Enter an Integer-“);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
printf(“\n%d”,i);
}
}
Output :-
Enter an Integer-10
1
2
3
4
5
6
7
8
9
10

36
33) Write a program of table of n.
#include<stdio.h>
void main()
{
int n,a,i;
printf(“enter the integer-“);
scanf(“%d”,&n);

for(i=1;i<=n;i++)
{
printf(“\n”);
for(a=1;a<=10;a++)
{
printf(“\n%d*%d=%d”,i,a,i*a);
}
}
}
Output. :-
Enter the integer-3

1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
1*6=6
1*7=7
1*8=8
1*9=9
1*10=10

2*1=2
2*2=4

37
2*3=6
2*4=8
2*5=10
2*6=12
2*7=14
2*8=16
2*9=18
2*10=20

3*1=3
3*2=6
3*3=9
3*4=12
3*5=15
3*6=18
3*7=21
3*8=24
3*9=27
3*10=30

38
34) Write a program to write a table of any number.
#include<stdio.h>
void main()
{
int i,n;
printf(“enter an integer—“);
scanf(“%d”,&n);
for(i=1;i<=10;i++)
{
printf(“%d×%d=%d\n”,n,i,n*i);
}
}
Output :-
Enter an integer—5
5×1=5
5×2=10
5×3=15
5×4=20
5×5=25
5×6=30
5×7=35
5×8=40
5×9=45
5×10=50

39
Function
35) Write a program to find the sum of two numbers by using
Functions.
#include<stdio.h>
int sum(int x,int y);
void main()
{
int a,b;
printf(“Enter two Numbers—“);
scanf(“%d%d”,&a,&b);
sum(a,b);
}
int sum(int x,int y)
{
printf(“The Sum is--%d\n”,x+y);
}
Output :-
Enter two Numbers—40 40
The Sum is—80

40
36) Write a program to find the area of rectangle by using functions.
#include<stdio.h>
int rec(int x,int y);
void main()
{
int l,b;
printf(“Enter the length and Breadth—“);
scanf(“%d%d”,&l,&b);
rec(l,b);
}
int rec(int x,int y)
{
printf(“The area of Rectangle is --%d\n”,x*y);
}
Output. :-
Enter the length and Breadth—5 4
The area of Rectangle is —20

41
37) Write a program to find the area of triangle by using functions.
#include<stdio.h>
float tri(float x,float y);
void main()
{
float h,b;
printf(“Enter the Height and Breadth—“);
scanf(“%f%f”,&h,&b);
tri(h,b);
}
float tri(float x,float y)
{
float c;
c=0.5*x*y;
printf(“The Area of Triangle is-%f”,c);
}
Output. :-
Enter the Height and Breadth—4 6
The Area of Triangle is-12.000000

42
38) Write a program to calculate sum of first n natural no. by using
Functions
#include<stdio.h>
int sum(int x);
void main()
{
int n;
printf(“enter the number—“);
scanf(“%d”,&n);
sum(n);
}
int sum(int x)
{
int i,sum=0;
for(i=0;i<=x;i++)
{
sum=sum+i;
}
printf(“the sum is-%d”,sum);
}
Output :-
Enter the Number—5
The Sum is-15

43
39) Write a program to find the factorial of any number by using
Functions.
#include<stdio.h>
int fact(int x);
void main()
{
int n;
printf(“enter the number—“);
scanf(“%d”,&n);
fact(n);
}
int fact(int x)
{
int i,fact=1;
for(i=1;i<=x;i++)
{
fact=fact*i;
}
printf(“the factorial is-%d”,fact);
}
Output :-
Enter the Number—5
The Factorial is-120

44
40) Write a program to print the table of any number by using
Functions.
#include<stdio.h>
int table(int x);
void main()
{
int n;
printf(“enter the number—“);
scanf(“%d”,&n);
table(n);
}
int table(int x)
{
int i;
for(i=1;i<=10;i++)
{
printf(“%d×%d=%d\n”,x,i,x*i);
}
}
Output. :-
Enter the Number—4
4×1=4
4×2=8
4×3=12
4×4=16
4×5=20
4×6=24
4×7=28
4×8=32
4×9=36
4×10=40

45
41) Write a program to convert degree to fraheniet by using functions.
#include<stdio.h>
float deg( float x);
void main()
{
float d;
printf(“convert degree celsius to fahrenheit\n”);
printf(“enter the degree—“);
scanf(“%f”,&d);
deg(d);
}
float deg( float x)
{
int a;
a=(1.8*x)+32;
printf(“the fahrenheit is--%f\n”,a);
}
Output. :-
Convert Degree Celsius to Fahrenheit
Enter the Degree—27
The Fahrenheit is—80.600000

46
42)Write a program to find the greater number between two numbers
By using functions.
#include<stdio.h>
int gret( int x,int y);
void main()
{
int a,b;
printf(“enter two numbers—“);
scanf(“%d%d”,&a,&b);
gret(a,b);
}
int gret( int x,int y)
{
if(x>y)
{
printf(“the greater number is %d”,x);
}
else
{
printf(“the greater number is %d”,y);
}
}
Output :-
Enter Two Numbers—54 32
The Greater Number is 54

47
43) Write a program to swap two value by using function
#include<stdio.h>
int swap(int x,int y);
void main()
{
int a,b;
printf(“enter the a and b”);
scanf(“%d%d”,&a,&b);
printf(“\nbefore swaping a=%d,b=%d”,a,b);
swap(a,b);
}
int swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;

printf(“\nafter swaping a=%d,b=%d”,x,y);


}
Output. :-
Enter the a and b5 7

Before Swaping a=5,b=7


After Swaping a=7,b=5

48
Pointer
44) Write a program to find the sum of two numbers by using pointer.
#include<stdio.h>
int sum(int *x,int *y);

void main()
{
int a,b;
printf(“enter two numbers—“);
scanf(“%d%d”,&a,&b);
sum(&a,&b);
}
int sum(int *x,int *y)
}
printf(“the sum is--%d\n”,*x+*y);
}
Output. :-
Enter two Numbers—52 4
The Sum is—56

49
45) Write a program to find the area of rectangle by using pointer.
#include<stdio.h>
int rec(int *x,int *y);

void main()
{
int l,b;
printf(“enter the length and breadth—“);
scanf(“%d%d”,&l,&b);
rec(&l,&b);
}
int rec(int *x,int *y)
{
printf(“the sum is--%d\n”,(*x)*(*y));
}
Output. :-
Enter the length and Breadth—5 7
The Sum is--35

50
46) Write a program to find the area of triangle by using pointer.
#include<stdio.h>
float tri(float *x,float *y);
void main()
{
float h,b;
printf(“enter the height and base—“);
scanf(“%f%f”,&h,&b);
tri(&h,&b);
}
float tri(float *x,float *y)
{
float c;
c=0.5*(*x)*(*y);
printf(“the area of triangle is-%f”,c);
}
Output. :-
Enter the Height and Base—6 2
The Area of Triangle is-6.000000

51
47) Write a program to calculate sum of first n natural no. by using
Pointer.
#include<stdio.h>
int sum(int *x);
void main()
{
int n;
printf(“enter the number—“);
scanf(“%d”,&n);
sum(&n);
}
int sum(int *x)
{
int i,sum=0;
for(i=0;i<=*x;i++)
{
sum=sum+i;
}
printf(“the sum is-%d”,sum);
}
Output :-
Enter the Number—10
The Sum is-55

52
48) Write a program to find the factorial of any number by using
Pointer.
#include<stdio.h>
int fact(int *x);
void main()
{
int n;
printf(“enter the number—“);
scanf(“%d”,&n);
fact(&n);
}
int fact(int *x)
{
int i,fact=1;
for(i=1;i<=*x;i++)
{
fact=fact*i;
}
printf(“the factorial is-%d”,fact);
}
Output. :-
Enter the Number—10
The factorial is-3628800

53
49) Write a program to print the table of any number by using
pointer.
#include<stdio.h>
int table(int *x);
void main()
{
int n;
printf(“enter the number—“);
scanf(“%d”,&n);
table(&n);
}
int table(int *x)
{
int i;
for(i=1;i<=10;i++)
{
printf(“%d×%d=%d\n”,*x,i,*x*i);
}
}
Output. :
Enter the Number—5
5×1=5
5×2=10
5×3=15
5×4=20
5×5=25
5×6=30
5×7=35
5×8=40
5×9=45
5×10=50

54
50) Write a program to convert degree to fraheniet by using pointer.
#include<stdio.h>
float deg( float *x);
void main()
{
float d;
printf(“convert degree celsius to fahrenheit\n”);
printf(“enter the degree—“);
scanf(“%f”,&d);
deg(&d);
}
float deg( float *x)
{
int a;
a=(1.8*(*x))+32;
printf(“the fahrenheit is--%f\n”,a);
}
Output. :-
Convert Degree Celsius to Fahrenheit
Enter the Degree—27
The Fahrenheit is—80.600000

55
51) Write a program to find the greater number between two
numbers By using pointer.
#include<stdio.h>
int gret( int *x,int *y);
void main()
{
int a,b;
printf(“enter two numbers—“);
scanf(“%d%d”,&a,&b);
gret(&a,&b);
}
int gret( int *x,int *y)
{
if(*x>*y)
{
printf(“the greater number is %d”,*x);
}
else
{
printf(“the greater number is %d”,*y);
}
}
Output :-
Enter Two Numbers—745 45
The Greater Number is 745

56
52) Write a program to swap two value by using pointer.
#include<stdio.h>
int swap(int *x,int *y);
void main()
{
int a,b;
printf(“enter the a and b”);
scanf(“%d%d”,&a,&b);
printf(“\nbefore swaping a=%d,b=%d”,a,b);
swap(&a,&b);
}
int swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;

printf(“\nafter swaping a=%d,b=%d”,*x,*y);


}
Output. :-
Enter the a and b78 3
Before Swaping a=78,b=3
After Swaping a=3,b=78

57
Array
53) Write a program for addition of array elements.
#include<stdio.h>
void main()
{
int a[100],i,n,sum=0;
printf(“Enter the array size-“);
scanf(“%d”,&n);
printf(“Enter the array elements-“);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“The Array Element is –”);
for(i=0;i<n;i++)
{
printf(“%d\n”,a[i]);
sum=sum+a[i];
}
printf(“The Addition of array element --%d”,sum);
}
Output :-
Enter the array size-4
Enter the array Elements-53 33 21 45
The array element is
53
33
21
45
The Addition of array element –152

58
54) Write a program for finding maximum and minimum number in
Array.
#include<stdio.h>
void main()
{
int i,j,n,a[100];
printf(“enter the array size-“);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
printf(“the array element is %d-\n”,i);
scanf(“%d”,&a[i]);
}
for(i=1;i<=n;i++)
{
if(a[1]<a[i])
{
a[1]=a[i];
}
}
printf(“the maximum no in array--%d\n”,a[1]);
for(i=1;i<=n;i++)
{
if(a[1]>a[i])
{
a[1]=a[i];
}
}
printf(“the minimum no in array--%d”,a[1]);
}
Output. :-
Enter the Array size-4

59
The array element is 1-77
The array element is 2-96
The array element is 3-33
The array element is 4-45
The maximum no in array—96
The Minimum no in array--33

60
55) Write a program for printing matrix.
#include<stdio.h>
void main()
{
int i,j,a[3][3];
printf(“enter the matrix--”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“the first matrix is-“);
for(i=0;i<3;i++)
{ printf(“\n”);
for(j=0;j<3;j++)
{
printf(“%d\t”,a[i][j]);
}
}
}
Output. :-
Enter the Matrix—3 4 8 3 4 5 4 7 3
The first Matrix is-
3 4 8
3 4 5
4 7 3

61
56) Write a program for addition and subtraction of matrix using
Array.
#include<stdio.h>
void main()
{
int i,j,a[2][2],b[2][2],c[2][2];
printf(“enter the first matrix—“);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“enter the second matrix—“);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(“%d”,&b[i][j]);
}
}

printf(“first matrix--\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(“\t%d”,a[i][j]);
} printf(“\n”);
}
printf(“second matrix--\n”);
for(i=0;i<2;i++)

62
{
for(j=0;j<2;j++)
{
printf(“\t%d”,b[i][j]);
} printf(“\n”);
}
printf(“\n\naddition of ab matrix--\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf(“\t%d”,c[i][j]);
} printf(“\n”);
}
printf(“\n\nsubtraction of ab matrix--\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf(“\t%d”,c[i][j]);
} printf(“\n”);
}
}
Output. :-
Enter the First Matrix—4 4 4 4
Enter the second Matrix—2 2 2 2
First Matrix—
4 4
4 4

63
Second Matrix—
2 2
2 2
Addition of AB Matrix—
6 6
6 6
Subtraction of AB Matrix—
2 2
2 2

64
57) Write a program for addition of 2 dimensional matrix using Array.
#include<stdio.h>
void main()
{
int i,j,a[2][2],b[2][2],c[2][2];
printf(“enter the first matrix—“);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“enter the second matrix—“);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(“%d”,&b[i][j]);
}
}

printf(“first matrix--\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(“\t%d”,a[i][j]);
} printf(“\n”);
}
printf(“second matrix--\n”);
for(i=0;i<2;i++)
{

65
for(j=0;j<2;j++)
{
printf(“\t%d”,b[i][j]);
} printf(“\n”);
}
printf(“\n\naddition of ab matrix--\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf(“\t%d”,c[i][j]);
} printf(“\n”);
}
}
Output :-
Enter the First Matrix—5 5 5 5
Enter the second Matrix—7 7 7 7
First Matrix—
5 5
5 5
Second Matrix—
7 7
7 7
Addition of AB Matrix—
12 12
12 12

66
58) write a program for addition 3 dimensional of matrix using array.
#include<stdio.h>
void main()
{
int i,j,k,a[2][2][2],b[2][2][2],c[2][2][2];
printf(“enter the first matrix-\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
scanf(“%d”,&a[i][j][k]);
}
}
}
printf(“enter the second matrix-\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
scanf(“%d”,&b[i][j][k]);
}
}
}
printf(“first matrix—“);
for(i=0;i<2;i++)
{ printf(“\n”);
for(j=0;j<2;j++)
{ printf(“\n”);
for(k=0;k<2;k++)

67
{
printf(“\t%d”,a[i][j][k]);
}
}
}
printf(“\n\nsecond matrix—“);
for(i=0;i<2;i++)
{ printf(“\n”);
for(j=0;j<2;j++)
{ printf(“\n”);
for(k=0;k<2;k++)
{
printf(“\t%d”,b[i][j][k]);
}
}
}
printf(“\n\naddition of matrix—“);
for(i=0;i<2;i++)
{ printf(“\n”);
for(j=0;j<2;j++)
{ printf(“\n”);
for(k=0;k<2;k++)
{
c[i][j][k]=a[i][j][k]+b[i][j][k];
printf(“\t%d”,c[i][j][k]);
}
}
}
}
Output. :-
Enter the first matrix-
3 3333333
Enter the second matrix-

68
77777777
First Matrix—

3 3
3 3

3 3
3 3

Second Matrix—

7 7
7 7

7 7
7 7

Addition of Matrix—

10 10
10 10

10 10
10 10

69
Structure
59) Write a program for printing name of book, its pages and its price
using structures.
#include<stdio.h>
struct book
{
char name[100];
int page;
float price;
};
void main()
{
int n,i;
printf(“how many record you-“);
scanf(“%d”,&n);
struct book b[n];
for(i=0;i<n;i++)
{
printf(“\nenter the books record \n”);
printf(“enter the name of book—“);
scanf(“%s”,b[i].name);
printf(“enter the book pages—“);
scanf(“%d”,&b[i].page);
printf(“enter the book price—“);
scanf(“%f”,&b[i].price);
}
for(i=0;i<n;i++)
{
printf(“\nbook name--%s\nbook pages--%d\nbook price--
%f\n\n\n”,b[i].name,b[i].page,b[i].price);
}
}

70
Output. :-
How many Record you-1

Enter the Books Record


Enter the Name of Book--Ramayan
Enter the Book Pages--1000
Enter the Book Price--1001

Book Name--Ramayan
Book Pages--1000
Book Price--1001.000000

71
60) Write a program for printing Name of employee, his Id and his
Salary.
#include<stdio.h>
struct employee
{
char name[100];
int id;
float sallary;
};
void main()
{
int n,i;
printf(“how many record you-“);
scanf(“%d”,&n);
struct employee e[n];
for(i=0;i<n;i++)
{
printf(“\nenter the employee record \n”);
printf(“enter the name of employee—“);
scanf(“%s”,e[i].name);
printf(“enter the employee id—“);
scanf(“%d”,&e[i].id);
printf(“enter the employee sallary—“);
scanf(“%f”,&e[i].sallary);
}
for(i=0;i<n;i++)
{
printf(“\nemployee name--%s\nemployee id--%d\nemployee sallary--
%f\n\n\n”,e[i].name,e[i].id,e[i].sallary);
}
}
Output. :-
Enter the Employee Record

72
Enter the Name of Employee—Suraj
Enter the Employee Id—209993
Enter the Employee sallary—15999

Employee Name—Suraj
Employee Id—209993
Employee sallary—15999.000000

73
61) Write a program for printing student name, his roll no, section
And fees paid
#include<stdio.h>
struct student
{
char name[100];
char section[50];
int roll;
float fees;
};
void main()
{
int n,i;
printf(“how many record you-“);
scanf(“%d”,&n);
struct student s[n];
for(i=0;i<n;i++)
{
printf(“\nenter the student record \n”);
printf(“enter the name of student—“);
scanf(“%s”,s[i].name);
printf(“enter the section of student—“);
scanf(“%s”,s[i].section);
printf(“enter the student roll number—“);
scanf(“%d”,&s[i].roll);
printf(“enter the student paid fees—“);
scanf(“%f”,&s[i].fees);
}
for(i=0;i<n;i++)
{

74
printf(“\nname--%s\nsection--%s\nroll no--%d\npaid fees
%f\n\n\n”,s[i].name,s[i].section,s[i].roll,s[i].fees);
}
}
Output. :-
How many Record you-1

Enter the Student Record


Enter the Name of Student—MayurBonde
Enter the section of Student—C
Enter the student roll number—37
Enter the student paid fees—40141

Name—MayurBonde
Section—C
Roll No—37
Paid Fees—40141.000000

75
String
62) Write a program for declaring string and initialize string
#include<stdio.h>
#include<string.h>
void main()
{
int i,n,s1[100][100];
printf(“enter the number of students—“);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“enter name %d student—“,i+1);
scanf(“%s”,&s1[i]);
}
printf(“%d students names-\n”,n);
for(i=0;i<n;i++)
{
printf(“%d.%s\n”,i+1,s1[i]);
}
}
Output. :-
Enter the number of Students—2
Enter name 1 Student—Mayur
Enter name 2 Student—Mihir
2 Students Names-
1.Mayur
2.Mihir

76
63)Write a program for initialize string and output a string.
#include<stdio.h>
#include<string.h>
void main()
{
int i,n,s1[100][100];
printf(“enter the number of students—“);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“enter name %d student—“,i+1);
scanf(“%s”,&s1[i]);
}
printf(“%d students names-\n”,n);
for(i=0;i<n;i++)
{
printf(“%d.%s\n”,i+1,s1[i]);
}
}
Output. :-
Enter the number of Students—2
Enter name 1 Student—Bonde
Enter name 2 Student—Mayur
2 Students Names-
1.Bonde
2.Mayur

77
64) Write a program for get input and print it using gets() and puts().
#include<stdio.h>
#include<string.h>
void main()
{
char s1[50];
printf(“enter the string-“);
gets(s1);

printf(“the string is—“);


puts(s1);
}
Output :-
Enter the string-Mayur
The String is—Mayur

78
65) Write a program for measure length of string without using String
library.
#include<stdio.h>
#include<string.h>
void main()
{
int len=0;
char s[10];

printf(“enter a string:”);
gets(s);
while(s[len]!=’\0’)
{
len++;
}
printf(“\nlength:%d”,len);
}
Output :-
Enter a string:SSBT
Length:4

79
66) Write a program for measure length of string using string library.
#include<stdio.h>
#include<string.h>
void main()
{
int l;
char s1[100];
printf(“enter the string—“);
gets(s1);

l=strlen(s1);
printf(“\nthe string is-%s\nlength is = %d”,s1,l);
}
Output:-
Enter the string—Bonde

The string is-Bonde


Length is = 5

80
67) Write a program for copy a string and paste it without using string
library.
#include<stdio.h>
void main()
{
int i,j;
char s1[100],s2[100];
printf(“enter the string”);
scanf(“%[^\n]%*c”,s1);
for(i=0;s1[i]!=<’\0’;i++)
{
s2[i]=s1[i];
}
printf(“\nthe original string is %s”,s1);
printf(“\nthe string after copying is %s”,s2);
}
Output :-
Enter the string Bonde
The original string is Bonde
The string after copying is Bonde

81
68) Write a program for copy a string and paste it using string Library.
#include<stdio.h>
#include<string.h>
void main()
{
char c,s1[100],s2[100];
printf(“enter the 1st string—“);
gets(s1);
printf(“enter the 2nd string—“);
gets(s2);

strcpy(s1,s2);
printf(“\nthe copy string is =%s”,s1);
printf(“\nthe 2nd string is =%s”,s2);
}
Output:-
Enter the 1st string—engineering
Enter the 2nd string—College

The Copy string is =College


The 2nd string is =College

82
69) Write a program for comparing a string without using string
Library.
#include<stdio.h>
#include<string.h>

void main()
{
char s1[100],s2[100];
int result, i;

printf("\n please enter the s1 string : ");


gets(s1);
printf("\n please enter the s2 string : ");
gets(s2);
for(i=0;s1[i]==s2[i] && s1[i]=='\0';i++);
if(s1[i]<s2[i])
{
printf("\n s1 is less than s2");
}
else if(s1[i]>s2[i])
{
printf("\ns2 is less than s1");
}
else
{
printf("\n s1 is equal to s2");
}
}
Output :-
Please Enter the s1 String : Mayur
Please Enter the s2 String : Mayur
s1 is Equal to s2

83
70) Write a program for comparing a string using string library.
#include<stdio.h>
#include<string.h>
void main()
{
int i;
char s1[100],s2[100];
printf(“enter the 1st string—“);
gets(s1);

printf(“enter the 2nd string—“);


gets(s2);

i=strcmp(s1,s2);
if(i==0)
{
printf(“\nstring are same”);
}
else
{
printf(“\nsrting are different”);
}
}
Output :-
Enter the 1st string—Jalgaon
Enter the 2nd string—Jalgaon

String are Same

84
71) Write a program for converting a string to lowercase
#include<stdio.h>
#include<string.h>
void main()
{
char s1[100];
int i;

printf(“enter the string—“);


gets(s1);

for(i=0;i<=strlen(s1);i++)
{
if(s1[i]>=’a’ && s1[i]<=’z’)
s1[i]=s1[i]+32;
}
printf(“lowercase string--%s”,s1);
}
Output :-
Enter the string—SSBT
Lowercase String—ssbt

85
72) Write a program for converting a string to uppercase.
#include<stdio.h>
#include<string.h>
void main()
{
char s1[100];
int i;

printf(“enter lowercase string—“);


gets(s1);

for(i=0;i<=strlen(s1);i++)
{
if(s1[i]>=’a’ && s1[i]<=’z’)
s1[i]=s1[i]-32;
}
printf(“uppercase string--%s”,s1);
}
Output. :-
Enter lowercase string—ssbt
Uppercase string—SSBT

86
73) Write a program for checking name in list (ask input from user and
declare some names already and compare them).
#include<stdio.h>
#include<string.h>
void fn(void);
void main()
{
fn();
}
void fn(void)
{
char a[50];
char b[]=”mayur”,c[]=”saket”,d[]=”deva”,e[]=”hemant”,f[]=”mihir”;
int i,j,k,l,m;
printf(“enter the name-”);
gets(a);
i=strcmp(b,a);
j=strcmp(c,a);
k=strcmp(d,a);
l=strcmp(e,a);
m=strcmp(f,a);
if(i==0||j==0||k==0||l==0||m==0)
{
printf(“\nyou are in the list”);
}
else
{
printf(“\nsorry.the person name not in the list”);
}
}
Output. :-Enter the Name-Saket
You are in the list

87
Different
74) Write a program for printing largest number in an Array.
#include<stdio.h>
void main()
{
int a[100],i,n;

printf(“enter the array size”);


scanf(“%d”,&n);

for(i=0;i<n;i++)
{
printf(“enter array element-“);
scanf(“%d”,&a[i]);
}

for(i=0;i<n;i++)
{
if(a[1]<a[i])
{
a[1]=a[i];
}
}
printf(“The Largest No Is %d”,a[1]);
}
Output. :-
Enter The Array Size-4
Enter Array Element-88
Enter Array Element-54
Enter Array Element-5
Enter Array Element-78
The Largest No Is 8

88
75) Write a program for printing array using pointer.
#include<stdio.h>
void main()
{
int n,a[100],*arr[100],i;

printf(“enter size of array =>”);


scanf(“%d”,&n);
printf(“enter the %d elements-“,n);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“array elements=>\n”);
for(i=0;i<n;i++)
{
arr[i]=&a[i];
printf(“%d\n”,*arr[i]);
}
}
Output. :-
Enter Size of array =>3
Enter the 3 elements-67 755 88
Array Elements=>
67
755
88

89
76) Write a program for specify data: Name, Roll no, Section, Total
marks in ISE and their percentage of 62 students using array.
#include<stdio.h>
struct student
{
char name[100];
char section[50];
int roll;
float marks;
float per;
};
void main()
{
int n,i;
printf(“how many record you-“);
scanf(“%d”,&n);
struct student s[n];
for(i=0;i<n;i++)
{
printf(“\nenter the student record \n”);
printf(“enter the name of student—“);
scanf(“%s”,s[i].name);
printf(“enter the section of student—“);
scanf(“%s”,s[i].section);
printf(“enter the student roll number—“);
scanf(“%d”,&s[i].roll);
printf(“enter the student 4-ise total marks—“);
scanf(“%f”,&s[i].marks);
s[i].per=(s[i].marks/40)*100;
}
for(i=0;i<n;i++)
{

90
printf(“\nname--%s\nsection--%s\nroll no--%d\ntotal marks--
%f\npercentage--
%f\n\n”,s[i].name,s[i].section,s[i].roll,s[i].marks,s[i].per);
}
}

Output. :-
How many Record you-1

Enter the Student Record


Enter the Name of Student—Kunal
Enter the section of Student—A
Enter the student roll number—21
Enter the student 4-ISE total marks—70

Name—Kunal
Section—A
Roll No—21
Total Marks—70.000000
Percentage—87.500000

91
77) Write a program to separate upper case and lower case letters
from input and print them separately
#include<stdio.h>
#include<string.h>
void main()
{
char s1[100];
int i;

printf(“enter string—“);
gets(s1);

for(i=0;i<strlen(s1);i++)
{
if(s1[i]>=’a’ && s1[i]<=’z’)
{
printf(“\n %c-Uppercase Letter”,s1[i]);
}
else{
printf(“\n %c-Lowercase Letter”,s1[i]);
}
}
}
Output. :-
Enter string—MaYuR

M-Uppercase Letter
a-Lowercase Letter
Y-Uppercase Letter
u-Lowercase Letter
R-Uppercase Letter

92
78) Write a program for multiplication of 2 dimensional arrays.
#include<stdio.h>
void main()
{
int i,j,a[2][2],b[2][2],c[2][2];
printf(“enter 4 element of first matrix—“);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“enter 4 element of second matrix—“);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(“%d”,&b[i][j]);
}
}
printf(“first matrix--\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(“\t%d”,a[i][j]);
} printf(“\n”);
}
printf(“second matrix--\n”);
for(i=0;i<2;i++)
{

93
for(j=0;j<2;j++)
{
printf(“\t%d”,b[i][j]);
} printf(“\n”);
}

printf(“\n\nmultiplication of ab matrix--\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]*b[i][j];
printf(“\t%d”,c[i][j]);
} printf(“\n”);
}
}
Output. :-
Enter 4 element of First Matrix—6 3 2 5
Enter 4 element of second Matrix—9 4 2 5
First Matrix—
6 3
2 5
Second Matrix—
9 4
2 5

Multiplication of AB Matrix—
54 12
4 25

94
79) Write a program for adding two strings which are taken from user.
#include<stdio.h>
#include<string.h>
void main()
{
char s1[100],s2[100];

printf(“enter string—“);
gets(s1);

printf(“enter string—“);
gets(s2);

strcat(s1,s2);

printf(“both string--%s”,s1);
}
Output. :-
Enter string—Mayur
Enter string—Bonde
Both String—Mayur Bonde

95
80) Write a program for printing * pyramid using loops.
#include<stdio.h>
void main()
{
int n,i,j,k;
printf(“enter the rows”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
for(j=n;j>i;j--)
{
printf(“ “);
}
for(k = 1;k <= ((j*2)-1);k++)
{
printf(“*”);
}
printf(“\n”);
}
}
Output. :-
Enter the rows-9
*
***
*****
*******
*********
***********
*************
***************
*****************

96
97

You might also like