1. Engineering
  2. Computer Science
  3. c programming no fflush to be used use a...

Question: c programming no fflush to be used use a...

Question details

C programming | No fflush to be used, use a basic for loop | Instead of repeating the same code five times – modify the code to use a FOR loop to ask for 5 user inputs. Use an input statement such as scanf(“%c”, &ch); to replace the assignment statements such as ch = '+';

#include <stdio.h> void main () char ch; int f, a = 10, b= 20; printf ( ch- %c\n , ch) ; switch (ch) case t: f- a + b; printf(f- %d\n, case -: f = a -b; printf(f = %d\n, case *: f- a * b; printf (f- %d\n, case /: f a / b; printf (f- %d\n, default: printf (invalid operator\n) f); f); f); f); a-10, b 20; printf ( ch- %c\n, switch (ch) ch); case +: f a + b; printf (f- %d\n, case -: f a - b; printf(f- %d\n, case *: f a * b; printf(f- %d\n, case /: f-a / b; printf(f- %d\n, default: printf (invalid operatorln); f); f); f); f); a-10, b20; printf (chcIn, ch) switch (ch) ( case +: f a + b; printf(f- %d\n, case -: f a - b; printf(f- %d\n, case *: f - a * b; printf (f- %d\n, case /: f = a / b; printf(f-%d\n, default: printf (invalid operator\n) f); f); f); f); a10, b20; printf ( ch- %c\n, switch (ch) ch) ; case t: f a + b; printf(f %d\n, case -: f = a - b; printf(f %d\n, case *: f a * b; printf (f- %d\n, case /: f a / b; printf(f- %d\n, default: printf (invalid operator\n) f); f); f); f); ch a = 10, b= 20; printf ( ch- %c\n, switch (ch) ch) ; case t: f a + b; printf(f- %d\n, case -: f a -b; printf (f- %d\n, case *: f a * b; printf( f %d\n, case /: f - a / b; printf(f- %d\n, default: printf (invalid operator n f); f); f); f);

REQUIRED OUTPUT:

f 30 f 1 f200 f 0.50 invalid operator

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution