- Addition
- Subtraction
- Multiplication
- Division
and display the result: Terminate the program when enter 'n'
The Answer is
int main()
{
float num1, num2;
char operation;
while (1) {
printf("Please enter 2 integer:");
scanf("%f%f", &num1, &num2);
printf("Enter an option(A for addition, B for subtraction, C for multiplication,\n D for division, n for exit):");
scanf("%s", &operation);
if (operation == 'A')
printf("%f\n", num1+num2);
if (operation == 'B')
printf("%f\n", num1-num2);
if (operation == 'C')
printf("%f\n", num1*num2);
if (operation == 'D')
printf("%f\n", num1/num2);
if (operation == 'n')
break;
}
}
#include <stdio.h>
int main()
{
float num1, num2;
char operation;
while (1) {
printf("Please enter 2 integer:");
scanf("%f%f", &num1, &num2);
printf("Enter an option(A for addition, B for subtraction, C for multiplication,\n D for division, n for exit):");
scanf("%s", &operation);
if (operation == 'A')
printf("%f\n", num1+num2);
if (operation == 'B')
printf("%f\n", num1-num2);
if (operation == 'C')
printf("%f\n", num1*num2);
if (operation == 'D')
printf("%f\n", num1/num2);
if (operation == 'n')
break;
}
}
0 comments:
Post a Comment