Question: Can you help me turn this switch statement into a for loop? Thank you, and could you show where each variable goes where. Use this
Can you help me turn this switch statement into a for loop? Thank you, and could you show where each variable goes where.
Use this statement to replace char ch = '+' : ch = getchar(); or scanf(%c , &ch);
char ch = '+';
int a = 10, b = 20;
int f;
printf("ch = %c ", ch);
switch (ch) {
case '+': f = a + b; printf("f = %d ", f);break;
case '-': f = a - b; printf("f = %d ", f);break;
case '*': f = a * b; printf("f = %d ", f);break;
case '/': f = a / b; printf("f = %d ", f);break;
default: printf("invalid operator ");
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
