0% found this document useful (0 votes)
6 views41 pages

Pps Programs

The document contains multiple C programming exercises, each with a specific aim such as calculating sums, checking conditions, and sorting arrays. Each section includes the code, expected output, and a date indicating when the exercise was created. The exercises cover a range of topics from basic arithmetic operations to more complex data handling using arrays and functions.

Uploaded by

Mr Iconic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views41 pages

Pps Programs

The document contains multiple C programming exercises, each with a specific aim such as calculating sums, checking conditions, and sorting arrays. Each section includes the code, expected output, and a date indicating when the exercise was created. The exercises cover a range of topics from basic arithmetic operations to more complex data handling using arrays and functions.

Uploaded by

Mr Iconic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

DATE :-19|9|24

AIM:-Write a C program to find the sum of two numbers


#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("enter the value of a:");
scanf("%d",&a);
printf("enter the value of b:");
scanf("%d",&b);
c=a+b;
printf("the sum of two number is: %d\n",c):
getch();
return 0;
}

Output :-
enter the value of a:15
enter the value of b:40
the sum of two number is: 55
DATE :-19|9|24
AIM:-Write a program to find the size of float , int , char
and long float datatype.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a=sizeof (float);
int b=sizeof (int);
int c=sizeof (char);
int d=sizeof (long float);
printf("the size of the float datatype : %d\n",a);
printf("the size of the integer datatype : %d\n",b);
printf("the size of the char datatype : %d\n",c);
printf("the size of the long float datatype : %d\n",d);
getch();
return 0;
}

Output :-
the size of the float datatype : 4
the size of the integer datatype : 2
the size of the char datatype : 1
the size of the long float datatype : 8
DATE :-19|9|24
AIM:-Write a C program to check AND gate.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("enter the first number:\n");
scanf("%d",&a);
printf("enter the second number:\n");
scanf("%d",&b);
c=a&b;
printf("the AND gate between first and second number is :%d\n",c);
getch();
return 0;
}

Output :-
enter the first number:5
enter the second number:39
the AND gate between first and second number is :5
DATE :-26|9|24
AIM:-Write a C program to check OR gate.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
printf("enter the first number :\n");
scanf("%d",&a);
printf("enter the second number :\n");
scanf("%d",&b);
c=a||b;
printf("the OR gate between first and second number is :%d\n",c);
getch();
return 0;
}

Output :-
enter the first number:5
enter the second number:39
the OR gate between first and second number is :39
DATE :-26|9|24
AIM:-Write a C program to shift the given number
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
printf("enter the number :\n");
scanf("%d",&a);
b=(a<<2);
printf("after shift number is :%d\n",b);
getch();
return 0;
}

Output :-
enter the number:2
after shift number is :8
DATE :-26|9|24
AIM:-Write a C program to convert minutes into years
and days .
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf(" enter the min to covert in years or in days");
scanf("%d",&a);
b=a/(24*365);
printf("the min in years : %d\n",b);
c=a/24;
printf("the min in days : %d\n",c);
getch();
return 0;
}

Output :-
enter the min to covert in years and in days :40272728929
the min in years : 3078
the min in days : 1123627
DATE:-3|10|24
AIM:-Write a C program to check whether number is
positive , negative or zero.
#include<stdio.h>
#include<conio.h>
int main()
{
float a;
clrscr();
printf("enter the number:");
scanf("%f",&a);
if (a==0)
printf("%f you entered 0");
if (a>0)
printf("%f is positive number",a);
else
printf("%f is negative number",a);
getch();
return 0;
}

Output :-
enter the number:4
4 is positive number
DATE :-3|10|24
AIM:-Write a C program to check whether the
number is even or odd.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
printf("enter the number:");
scanf("%d",&a);
if (a%2==0)
printf("the number is even ");
else
printf("thr number is odd ");
getch();
return 0;
}

Output :-
enter the number:8
the number is even
DATE :-3|10|24
AIM:-Write a C program to input week number and print week day.
#include<stdio.h>
#include<conio.h>
int main(){
int day;
clrscr();
printf("enter the day");
scanf("%d",&day);
switch (day)
{
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
defult:
printf("invalid case ");
}
getch();
return 0;
}

Output :-
enter the day : 5
Friday
DATE :-17|10|24
AIM:-Write a program to enter two number and find their sum
and difference.
#include<stdio.h>
#include<conio.h>
int main(){
float a,b,c,d,e;
int operation;
clrscr();
printf("enter the first number:");
scanf("%f",&a);
printf("enter the second number:");
scanf("%f",&b);{
printf("for sum enter 1\n ");
printf("for difference enter 2\n");
scanf("%d",&c);
}
if (c==1){
d=a+b;
printf("the sum is %f",d);
}
if (c==2){
e=a-b;
printf("the difference is %f",e);
}
else{
printf("invalid case");
}
getch();
return 0;
}
Output :-
enter the first number:6
enter the second number:30
for sum enter 1
for difference enter 2
1
The sum is 36
DATE :-17|10|24
AIM:-Write a C program using loop.
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,sum=0;
clrscr();
for(i=1;i<=5;i++)
{
sum=sum+i;
}
printf("%d\n",sum);
getch();
return 0;
}

Output :-
15
DATE :-17|10|24
AIM:-Write a program to display table of any number .
#include<stdio.h>
#include<conio.h>
int main()
{
int a,i;
clrscr();
printf(" enter the number of table you want:");
scanf("%d",&a);
for(i=1;i<=10;i++)
{
printf("%d x %d =%d\n",a,i,a*i);
}
getch();
return 0;
}
Output :-
Enter the number of table you want:5
5x1=1
5x2=10
5x3=15
5x4=20
5x5=25
5x6=30
5x7=35
5x8=40
5x9=45
5x10=50
DATE :-24|10|24
AIM :- Write a c program to take input and display it
using array function.
#include<stdio.h>
#include<conio.h>
int main ()
{
int cmarks[2];
clrscr();
printf("enter the first marks:");
scanf("%d",&cmarks[0]);
printf("enter the second marks:");
scanf("%d",&cmarks[1]);
printf("the first marks is : %d\n",cmarks[0]);
printf("the second marks is : %d\n",cmarks[1]);
getch();
return 0;
}

Output :-
enter the first marks :35
enter the second marks :30

the first marks is : 35


the second marks is : 30
DATE :-24|10|24
AIM:-Write a C program to find the average of 5 subjects
#include<stdio.h>
#include<conio.h>
int main()
{
int cmarks[5];
int sum =0;
float avg ;
int count=5;
int i ;
clrscr();
printf("enter the marks of 5 subjects \n");
for(i=0;i<count;i++){
printf("%d>",i+1);
scanf("%d",&cmarks[i]);
sum=sum+cmarks[i];
}
avg=sum/count;
printf("the avg marks is :%f",avg);
getch();
return 0;
}
Output :-
enter the marks of 5 subjects
1>40
2>39
3>37
4>34
5>32
the avg marks is:36.400002
DATE :-24|10|24
AIM:-Write a c program to sum of two one dimension matrix
#include<stdio.h>
#include<conio.h>
int main()
{
int i,a[2],b[2],c[2];
clrscr();
printf("enter the value of first matrix: \n");
for(i=0;i<2;i++){
scanf("%d",&a[i]);
}
printf("enter the value of second matrix: \n");
for(i=0;i<2;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<2;i++)
{
c[i]=a[i]+b[i];
}
for(i=0;i<2;i++)
{
printf("%d",c[i]);
}
getch();
return 0;
}
Output :-
Enter the value of first matrix:
1
2
Enter the value of second matrix:
5
2
Sum=
6
4
DATE :-21|11|24
AIM:-Write a program to to add two matrix of two dimension
#include<stdio.h>
#include<conio.h>
int main()
{
int a[2][2],b[2][2],c[2][2],i,j;
clrscr();
printf("enter the value of first matrix :\n");
for (i=0;i<2;i++)
for (j=0;j<2;j++){
scanf("%d",&a[i][j]);
}
printf("enter the value of second matrix :\n");
for (i=0;i<2;i++)
for (j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
for (i=0;i<2;i++)
for (j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
for (i=0;i<2;i++)
for (j=0;j<2;j++)
{
printf("%d",c[i][j]);
}
getch();
return 0;
}

Output :-
Enter the value of first matrix:
1
2
3
4
Enter the value of second matrix:
5
2
9
7
Sum =
6
4
12
11
DATE :-21|11|24
AIM:-Write a C program to find the largest integer among
the given integer.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a[50];
int i,n;
int large=0;
printf("enter the number of elements:");
scanf("%d",&n);
for (i=0;i<n;i++)
{
printf("enter the elements");
scanf("%d",&a[i]);
}
for (i=0;i<n;i++)
{
if (a[i]>large)
large=a[i];
}
printf("the largest number is %d",large);
getch();
return 0;
}
Output :-

Enter the number of elements:4


Enter the elements:73
Enter the elements:45
Enter the elements:79
Enter the elements:13

The largest number is 79


DATE :-21|11|24
AIM :-Write a C program to arrange the given
integer in Ascending order using Selection sorting.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a[5];
int b,c,temp=0,i;
for (b=0;b<5;b++)
{
printf("enter the elements");
scanf("%d",&a[b]);
}
for(i=0;i<5;i++)
{
if(a[0]>a[1])
{
temp=a[0];
a[0]=a[1];
a[1]=temp;
}
if(a[0]>a[2])
{
temp=a[0];
a[0]=a[2];
a[2]=temp;
}
if(a[0]>a[3])
{
temp=a[0];
a[0]=a[3];
a[3]=temp;
}
if(a[0]>a[4])
{
temp=a[0];
a[0]=a[4];
a[4]=temp;
}
if(a[1]>a[2])
{
temp=a[1];
a[1]=a[2];
a[2]=temp;
}
if(a[1]>a[3])
{
temp=a[1];
a[1]=a[3];
a[3]=temp;
}
if(a[1]>a[4])
{
temp=a[1];
a[1]=a[4];
a[4]=temp;
}
if(a[2]>a[3])
{
temp=a[2];
a[2]=a[3];
a[3]=temp;
}
if(a[2]>a[4])
{
temp=a[2];
a[2]=a[4];
a[4]=temp;
}
if(a[3]>a[4])
{
temp=a[3];
a[3]=a[4];
a[4]=temp;
}
printf("%d ",a[i]);
}
getch();
return 0;
}

Output :-

Enter the elements 14


Enter the elements 62
Enter the elements 73
Enter the elements 63
Enter the elements 6
6 14 62 63 73
DATE :-28|11|24
AIM :-Write a C program to arrange the given
integer in Ascending order using selection sorting
with the help of loop.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a[5];
int i,j,b,c,temp=0;
for (b=0;b<5;b++)
{
printf("enter the integer:");
scanf("%d",&a[b]);
}
for (i=0;i<5;i++)
{
for (j=0;j<5;j++)
if (a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
for (c=0;c<5;c++)
printf("%d ",a[c]);
getch();
return 0;
}

Output :-

Enter the integer 19


Enter the integer 66
Enter the integer 73
Enter the integer 33
Enter the integer 8
8 19 33 66 73
DATE :-28|18|24
AIM :-Write a C program to arrange the given
integer in Ascending order using bubble sorting.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a[5];
int i,j,b,c,temp=0;
for(b=0;b<5;b++)
{
printf("enter the integers:");
scanf("%d",&a[b]);
}
for (i=0;i<5;i++)
{
for (j=0;j<5-i;j++)
{
if (a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for (c=0;c<5;c++)
printf("%d ",a[c]);
getch();
return 0;
}

Output :-

Enter the integer 5


Enter the integer 65
Enter the integer 23
Enter the integer 67
Enter the integer 32
5 23 32 65 67
DATE :-28|11|24
AIM:-Write a C program to arrange the given
integerIn Ascending using Insertion Sorting .
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a[5]={19,87,4,32,8};
int i,j,key;
int n=5;
for (i=1;i<n;i++){
key=a[i];
for(j=i-1;j>=0 & a[j]>key;j--)
{
a[j+1]=a[j];
a[j]=key;
}
}
for(i=0;i<5;i++)
printf("%d\t",a[i]);
getch();
return 0;
}
Output :-
4 8 19 32 87
DATE :-5|12|24
AIM:-Write a C program using functions.
#include<stdio.h>
#include<conio.h>
void multi(float x,float y)
{
float result=x*y;
printf("the product of %f multiplied %f is: %f\n",x,y,result);
}
int main(void)
{
clrscr();
float x,y;
printf("enter the first number: ");
scanf("%f",&x);
printf("enter the second number:");
scanf("%f",&y);
multi(x,y);
getch();
return 0;
}
Output :-
Enter the first number:5
Enter the second number :10
The product of 5 multiplied 10 is: 50.000000
DATE :-5|12|24
AIM:-Write a C program using binary search.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int a[5]={1,2,3,4,5};
int key,l=0,r=4,m,f=0;
printf("enter key:");
scanf("%d",&key);
while(l<=r)
{
m=(l+r)/2;
if(key==a[m])
{
printf("found at index %d",m);
f=1;
break;
}
else if(key<a[m])
{
r+m-1;
}
else
{
l=m+1;
}
}
if(f==0)
{
printf("not found");
}
getch();
return 0;
}

Output :-

Enter the key:3


found at index
DATE :5|12|24
AIM:-Write a C program to find the factorial of given
number using functions .
#include<stdio.h>
#include<conio.h>
int fact(num)
{
int i,a=1;
for(i=1;i<=num;i++)
a=a*i;
printf("the factorial of %d! is %d ",num,a);
return num;
}
int main ()
{
int num;
clrscr();
printf("the enter the number:");
scanf("%d",&num);
fact( num);
getch ();
return 0;
}

Output:-

Enter the number :5


The factorial of 5 is 120
DATE :12|12|24
AIM:-Write a C program to swap of two number using call
by Value function.
#include<stdio.h>
#include<conio.h>
void swap( int a ,int b )
{
int temp;
temp=a;
a=b;
b=temp;
printf("the new values are %d %d ",a,b);
}
void main()
{
int a,b;
clrscr();
printf("enter the two numbers");
scanf("%d %d",&a,&b);
swap(a,b);
getch();
}
Output:-
Enter the two number 34 67
The new values are 67 34
DATE :12|12|24
AIM:-Write a C program to swap of two number using call
by Reference function.
#include<stdio.h>
#include<conio.h>
void swap( int *a ,int *b )
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void main()
{
int *a,*b;
clrscr();
printf("enter the two numbers");
scanf("%d %d",&*a,&*b);
swap(&*a,&*b);
printf("the new values are %d %d ",*a,*b);
getch();
}
Output:-
Enter the two number 63 98
The new values are 98 63
DATE :12|12|24
AIM:-Write a C program to find the factorial of given
number using Recursion.
#include<stdio.h>
#include<conio.h>
int factorial(int n)
{
if(n==0)
return 1 ;
else
return n*factorial(n-1);
}
int main()
{
int d,s;
clrscr();
printf("enter the number:\n");
scanf("%d",&s);
d=factorial(s);
printf("the factorial of %d is %d",s,d);
getch();
}
Output:-
enter the number :3
the factorial of 3 is 6
DATE :19|12|24
AIM:-Write a C program using pointers .
#include<stdio.h>
#include<conio.h>
int main()
{
int a,*pa;
clrscr();
printf("enter the value of a:");
scanf("%d",&a);
*pa=*(&a);
printf("%d %p %d",a,*pa,pa);
getch();
return 0;
}

Output:-
enter the value of a:45
45 002D 1258
DATE :19|12|24
AIM:-Write a C program using generic pointer .
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int x=10;
char ch='a';
float f=0.25;
void *gp;
gp=&x;
printf("\n generic pointer points to the integer value
=%d",*(int*)gp);
gp=&ch;
printf("\n generic pointer points to the character =%c",*(char*)gp);
gp=&f;
printf("\n generic pointer points to the float =%f",*(float*)gp);
getch();
return 0;
}
Output:-
generic pointer points to the integer value=10
generic pointer points to the character=a
generic pointer points to the float=0.250000
DATE :19|12|24
AIM:-Write a C program to enter student name ,
branch, roll no ,fees using structures.
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20],branch[20];
int roll_no,fees;
};
int main()
{
int i,n;
clrscr();
printf("\n enter the number of students:");
scanf("%d",&n);
struct student stud[10];
for(i=0;i<n;i++)
{
printf("\n enter the student %d,branch,roll_no,fees:",i+1);
scanf("%s %s %d %d", &stud[i].name ,&stud[i].branch ,
&stud[i].roll_no ,&stud[i].fees);
}
for(i=0;i<n;i++)
{
printf(" student: %d\n name: %s\n branch: %s\n roll_no: %d\n
fees:
%d\n",i+1,stud[i].name,stud[i].branch,stud[i].roll_no,stud[i].fees);
}
getch();
return 0;
}
Output:-
enter the number of students:2
enter the student 1 , branch , roll_no , fees:himanshu Cse 4 40000
enter the student 2 , branch , roll_no , fees:prashant Cse 42 40000

student: 1
name: himanshu
branch: Cse
roll_no: 4
fees: 40000

student: 2
name: prashant
branch: Cse
roll_no: 42
fees: 40000

You might also like