Question:1
C program to assume two numbers calculate and print their sum, product, difference, and average?
Sol:
#include<stdio.h>
int main()
{
int a=10,b=20,s,p,d;
float av;
s=a+b;
p=a*b;
d=a-b;
av=(float)(a+b)/2;
printf("Sum = %d\n",s);
printf("Product = %d\n",p);
printf("difference = %d\n",d);
printf("average = %f\n",av);
return 0;
}
Output:
Sum = 30 Product = 200 difference = -10 average = 15.000000
Question:2
C program to take input for two numbers calculate and print their sum, product, difference and average?
Sol:
#include<stdio.h>
int main()
{
int a,b,s,p,d;
float av;
printf("Enter 1st no ");
scanf("%d",&a);
printf("Enter 2nd no ");
scanf("%d",&b);
s=a+b;
p=a*b;
d=a-b;
av=(float)(a+b)/2;
printf("Sum = %d\n",s);
printf("Product = %d\n",p);
printf("difference = %d\n",d);
printf("average = %f\n",av);
return 0;
}
Output:
Enter 1st no 25 Enter 2nd no 63 Sum = 88 Product = 1575 difference = -38 average = 44.000000
Question:3
C program to convert total days into weeks and days.
Sol:
#include<stdio.h>
int main()
{
int d,w;
printf("Enter total days ");
scanf("%d",&d);
w=d/7;
d=d%7;
printf("week %d days %d",w,d);
return 0;
}
Output:
Enter total days 10 week 1 days 3
Question:4
C program to convert total inches into feet and inches.
Sol:
#include<stdio.h>
int main()
{
int in,f;
printf("Enter total inches ");
scanf("%d",&in);
f=in/12;
in=in%12;
printf("feet %d inches %d",f,in);
return 0;
}
Output:
Enter total inches 25 feet 2 inches 1 Enter total inches 35 feet 2 inches 11




