Aim:
To write a program to read two numbers and print the sum, difference, product and
quotient of the two numbers.
Algorithm:
1. Read the numbers a,b;
2. Calculate
Sum=a+b
Difference=a-b
Product=a*b
Quotient=a/b
3. Print sum, difference, product and the quotient.
4. Stop
Program:
/* Program to find sum, difference, product and quotient */
#include<conio.h>
#include<stdio.h>
void main()
{
float a,b,sum,diff,pro,quo;
clrscr();
printf("Enter the value for A:");
scanf("%f",&a);
printf("Enter the value for B(B<>0):");
scanf("%f",&b);
sum=a+b;
diff=a-b;
pro=a*b;
quo=a/b;
printf("\n\tThe sum of %.2f and %.2f = %.2f",a,b,sum);
printf("\n\tThe difference of %.2f and %.2f= %.2f",a,b,diff);
printf("\n\tThe product of %.2f and %.2f = %.2f",a,b,pro);
printf("\n\tThe quotient of %.2f by %.2f = %.2f",a,b,quo);
getch();
}
Output:
Enter the value for A:7
Enter the value for B(B<>0):5
The sum of 7.00 and 5.00 = 12.00
The difference of 7.00 and 5.00= 2.00
The product of 7.00 and 5.00 = 35.00
The quotient of 7.00 by 5.00 = 1.40
To write a program to read two numbers and print the sum, difference, product and
quotient of the two numbers.
Algorithm:
1. Read the numbers a,b;
2. Calculate
Sum=a+b
Difference=a-b
Product=a*b
Quotient=a/b
3. Print sum, difference, product and the quotient.
4. Stop
Program:
/* Program to find sum, difference, product and quotient */
#include<conio.h>
#include<stdio.h>
void main()
{
float a,b,sum,diff,pro,quo;
clrscr();
printf("Enter the value for A:");
scanf("%f",&a);
printf("Enter the value for B(B<>0):");
scanf("%f",&b);
sum=a+b;
diff=a-b;
pro=a*b;
quo=a/b;
printf("\n\tThe sum of %.2f and %.2f = %.2f",a,b,sum);
printf("\n\tThe difference of %.2f and %.2f= %.2f",a,b,diff);
printf("\n\tThe product of %.2f and %.2f = %.2f",a,b,pro);
printf("\n\tThe quotient of %.2f by %.2f = %.2f",a,b,quo);
getch();
}
Output:
Enter the value for A:7
Enter the value for B(B<>0):5
The sum of 7.00 and 5.00 = 12.00
The difference of 7.00 and 5.00= 2.00
The product of 7.00 and 5.00 = 35.00
The quotient of 7.00 by 5.00 = 1.40
No comments:
Post a Comment