Question: Write a for-loop in C using the instructins below for this code: /* This C program demonstrates the switch statement without using breaks. */ /*

Write a for-loop in C using the instructins below for this code:

/* This C program demonstrates the switch statement without using breaks. */

/* The program is tested on MS Visual C++ platform */

#include

#pragma warning(disable : 4996)

void main() {

char ch;

ch = '+';

int f, a = 10, b = 20;

printf("ch = %c ", ch);

switch (ch) {

case '+': f = a + b; printf("f = %d ", f);

case '-': f = a - b; printf("f = %d ", f);

case '*': f = a * b; printf("f = %d ", f);

case '/': f = a / b; printf("f = %d ", f);

default: printf("invalid operator ");

}

ch = '-';

printf("ch = %c ", ch);

switch (ch) {

case '+': f = a + b; printf("f = %d ", f);

case '-': f = a - b; printf("f = %d ", f);

case '*': f = a * b; printf("f = %d ", f);

case '/': f = a / b; printf("f = %d ", f);

default: printf("invalid operator ");

}

ch = '*';

printf("ch = %c ", ch);

switch (ch) {

case '+': f = a + b; printf("f = %d ", f);

case '-': f = a - b; printf("f = %d ", f);

case '*': f = a * b; printf("f = %d ", f);

case '/': f = a / b; printf("f = %d ", f);

default: printf("invalid operator ");

}

ch = '/';

printf("ch = %c ", ch);

switch (ch) {

case '+': f = a + b; printf("f = %d ", f);

case '-': f = a - b; printf("f = %d ", f);

case '*': f = a * b; printf("f = %d ", f);

case '/': f = a / b; printf("f = %d ", f);

default: printf("invalid operator ");

}

ch = '%';

printf("ch = %c ", ch);

switch (ch) {

case '+': f = a + b; printf("f = %d ", f);

case '-': f = a - b; printf("f = %d ", f);

case '*': f = a * b; printf("f = %d ", f);

case '/': f = a / b; printf("f = %d ", f);

default: printf("invalid operator ");

}

}

Write a for-loop in C using the instructins below for this code:

Expected Output:

/* This C program demonstrates the switch statement without using breaks. */

2.3 Use a for-loop in the code given above to accept 5 user inputs. Use an input statement such as ch = fgetchar0: to replace the assignment statement ch'+'; You can use either GCC or Visual Studio to complete this question. Please refer to the expected output word document for further clarification. Submit the rewritten progranm 10 points] Note, you may need to use fflush(stdin) to flush the newline character left behind by a previous operation before using fflush(stdin)

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!