1. Q.1 WAP in C/ C++/ java to perform the following tasks :
a. Accept two
numbers from the user( a and b).
b. Print the
numbers.
c. Print the
smallest number.
d. Calculate
their :
i.
Summation (a+b)
ii.
Subtract them (a-b)
iii.
Multiply them (a*b)
iv.
Divide them (a/b – quotient)
v.
Remainder (a%b)
vi. Square root of each number.
Solution :
#include<stdio.h>
#include<math.h> // to import math functions e.g. pow, sqrt, etc.
void main()
{
int a,b;
printf("\nEnter first number, a = ");
scanf("%d",&a);printf("Enter second number, b = ");
scanf("%d",&b);
printf("\nYour numbers are :\n");
printf("a = %d and ", a);
printf("b = %d\n", b);
if (a>b)
{
printf("%d is greater\n",a);
}
else if(b>a)
{
printf("%d is greater\n",b);
}
else
printf("Numbers are equal.\n");
printf("\nSummation is %d\n", a+b);
printf("a - b = %d\n", a-b);
printf("a x b = %d\n",a*b);
printf("\nNow we will divide a by b, we get\n");
printf(" Quotient = %d and ",a/b);
printf("remainder = %d\n", a%b);
printf("\nSquare root of a = %f\n", sqrt(a));
printf("Square root of b = %f\n", sqrt(b));
} // end of main()
Output :
Comments
Post a Comment