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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!