Program that will take two numbers X and Y as inputs,
then calculate and print the values of their addition,
subtraction, multiplication, division (quotient and
reminder).
Sample input (X,Y)Sample output
5 10 Addition: 15
Subtraction: -5
Multiplication: 50
Quotient : 0
Reminder: 5
-5 10.5 Addition: 5.5
Subtraction: -15.5
Multiplication: -52.5
Quotient: 0
Reminder: -48
Program that will take two numbers (a, b) as inputs and
compute the value of the equation – (Without using math.h)
X = (3.31 * a2 + 2.01 * b3) / (7.16 * b2 + 2.01 * a3)
Sample input (a, b)Sample output
5 10.5 X = 2.315475
100 -250 X = -12.766287
Program that will increment and decrement a number
X by 1 inside the printf function.
(Use ++ and - - operators)
Sample input(X)Sample output
5 X++ : 5
++X : 6
X-- : 5
--X : 4
-5 X++ : -5
++X : -4
X-- : -5
--X : -6
#include<stdio.h>
int main(){
int x,y;
scanf("%d",&x);
y=x;
printf("\nX++:%d",x++);
x=y;
printf("\n++X:%d",++x);
x=y;
printf("\nX--:%d",x--);
x=y;
printf("\n--X:%d",--x);
return 0;
}
Program that will increment and decrement a number X by Y.
(Use += and -= operators)
Sample input(X,Y)Sample output
5 10 Incremented Value: 10
Decremented Value: -5
-5 5 Incremented Value: 0
Decremented Value: -10
#include<stdio.h>
int main(){
int x,y,a,b;
scanf("%d %d",&x,&y);
a=x;
b=y;
printf("\nIncremented Value:%d",(x+=y));
x=a;
y=b;
printf("\nDecremented Value:%d",(x-=y));
return 0;
}
Program that will multiply and divide a number X by Y. (Use *= and /= operators)
Sample input(X,Y)Sample output
56 10 Multiplication: 560
Division: 5
-56 -10 Multiplication: 560
Division: 5
#include<stdio.h>
int main(){
int x,y,a,b;
scanf("%d %d",&x,&y);
a=x;
b=y;
printf("\nMultiplication:%d",(x*=y));
x=a;
y=b;
printf("\nDivision:%d",(x/=y));
return 0;
}
Program that will declare and initialize an integer and
a floating point number. Then it will perform floating to
integer and integer to floating conversions using
(a) Assignment operation
(b) Type casting
Sample inputSample output
-150 123.125 Assignment: 123.125000 assigned to an int produces 123
Assignment: -150 assigned to a float produces -150.000000
Type Casting: (float) -150 produces -150.000000
Type Casting: (int) 123.125 produces -123
#include<stdio.h>
int main(){
int a;
float b;
scanf("%d %f",&a,&b);
int a1=a;
float b1=b;
a=b;
printf("\nAssignment: %f assigned to an int produces: %d",b,a);
a=a1;
b=a;
printf("\nAssignment: %d assigned to a float produces %f",a,b);
b=b1;
printf("\nType Casting: (float) %d produces %f",a,(float)a);
printf("\nType Casting: (int) %f produces %d",b,(int)b);
return 0;
}
Program that will take two numbers as inputs and
print the maximum value. (Using conditional operator - ?)
Sample input (x, y)Sample output
20 100 Max: 100
50 -20 Max: 50
#include<stdio.h>
int main(){
int a,b;
scanf("%d %d",&a,&b);
(a>b)?printf("Max:%d",a):printf("Max:%d",b);
return 0;
}
Program that will evaluate the following equations -
X = a – b / 3 + c * 2 – 1
Y = a – ( b / ( 3 + c ) * 2) - 1
Z = a – ( ( b / 3) + c * 2) - 1
Sample input (a, b, c)Sample output
9 12 3 X = 10
Y = 4
Z = -15
#include<stdio.h>
int main(){
int a,b,c,x,y,z;
scanf("%d %d %d",&a,&b,&c);
x = a-(b/3)+(c*2)-1;
y = a-(b/(3+c)*2)-1;
z = a-((b/3)+c*2)-1;
printf("\nX = %d",x);
printf("\nY = %d",y);
printf("\nZ = %d",z);
return 0;
}