please write program in C language and show that it works in the compiler. 10, w
ID: 3828881 • Letter: P
Question
please write program in C language and show that it works in the compiler.
Explanation / Answer
#include <stdio.h>
int main()
{
char yes;
int a, b, c, choice;
printf("Enter first integer: ");
scanf("%d", &a);
yes = 'y';
while(yes == 'y' || yes == 'Y')
{
printf("Enter new integer: ");
scanf("%d", &b);
printf(" Add(1), Subtract(2), Multiply(3), Divide(4): ");
scanf("%d", &choice);
printf(" ");
switch(choice)
{
case(1):
c = a + b;
printf("%d + %d = %d ", a, b, c);
break;
case(2):
c = a - b;
printf("%d - %d = %d ", a, b, c);
break;
case(3):
c = a * b;
printf("%d * %d = %d ", a, b, c);
break;
case(4):
c = a / (float)b;
printf("%d / %d = %d ", a, b, c);
break;
default:
printf("Incorrect choice. Try again. ");
}
printf(" Again (Y/N): ");
scanf(" %c", &yes);
a=c;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.