Question

Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main()...

Construct a flowchart based on this code and write its equivalent algorithms.

#include <stdio.h>

int main()
{
int x,y;
float result;
char ch; //to store operator choice

printf("Enter first number: ");
scanf("%d",&x);
printf("Enter second number: ");
scanf("%d",&y);

printf("Choose operation to perform (+,-,*,/): ");
scanf(" %c",&ch);

result=0;
switch(ch)
{
case '+':
result=x+y;
break;

case '-':
result=x-y;
break;

case '*':
result=x*y;
break;

case '/':
result=(float)x/(float)y;
break;

case '%':
result=x%y;
break;
default:
printf("Invalid operation.\n");
}

printf("Result: %d %c %d = %.2f\n",x,ch,y,result);
// Directly print the number with .2f precision
printf("\n\n Input new number to try again/ n to exit):");
getchar();
ch=getchar();
if (ch !='n')
   {
       return main();
   }
   else
   {
       printf("\n\n Have a Nice Day!");
   }
   return 0;
}

Homework Answers

Answer #1

FLOW CHART


The code:

#include <stdio.h>

int main()
{
int x,y;
float result;
char ch; //to store operator choice

printf("Enter first number: ");
scanf("%d",&x);
printf("Enter second number: ");
scanf("%d",&y);

printf("Choose operation to perform (+,-,*,/): ");
scanf(" %c",&ch);

result=0;
switch(ch)
{
case '+':
result=x+y;
break;

case '-':
result=x-y;
break;

case '*':
result=x*y;
break;

case '/':
result=(float)x/(float)y;
break;

case '%':
result=x%y;
break;
default:
printf("Invalid operation.\n");
}

printf("Result: %d %c %d = %.2f\n",x,ch,y,result);
// Directly print the number with .2f precision
printf("\n\n Input new number to try again/ n to exit):");
getchar();
ch=getchar();
if (ch !='n')
   {
       return main();
   }
   else
   {
       printf("\n\n Have a Nice Day!");
   }
   return 0;
}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
What would appear in the console window after the code below executes? #include <stdio.h> int main()...
What would appear in the console window after the code below executes? #include <stdio.h> int main() { char myLetter = 'A'; printf("The value of A is %d", myLetter); }
2. Calculate number of times hello is printed. #include <stdio.h> #include <sys/types.h> int main() { fork();...
2. Calculate number of times hello is printed. #include <stdio.h> #include <sys/types.h> int main() { fork(); fork(); fork(); printf("hello\n"); return 0; }
#include <stdio.h> #include <stdlib.h> int main () { int k; int aux; int size = 8;...
#include <stdio.h> #include <stdlib.h> int main () { int k; int aux; int size = 8; int x[8] = {2, 3, 5, 7, 11, 13, 17, 19}; scanf("%d",&k); aux = x[k]; for (int i = k; i < size - 1; i++) x[i] = x[ i + 1]; x[ size - 1] = aux;   for (int i = 0; i < size; i++) printf("%d ", x[i]); } change this program to Write a program to remove an element from an...
int main() { while (1) { float d; scanf("%f", &d); float x; for (x = d;...
int main() { while (1) { float d; scanf("%f", &d); float x; for (x = d; x <= d + 1000.0; x = x + 1000.0) { } printf("loop exited with x = %.14g\n", x); } return 0; } If you run the program, you will see. What number should I use as an input to make this an infinite loop?
#include <stdio.h> extern unsigned long long sum(unsigned int *array, size_t n); int main(void) { unsigned int...
#include <stdio.h> extern unsigned long long sum(unsigned int *array, size_t n); int main(void) { unsigned int array[] = { 1, 1, 1, 3 }; unsigned long long r = sum(array, sizeof(array) / sizeof(*array)); printf("Result is: %llu (%s)\n", r, r == 6 ? "correct" : "incorrect"); return 0; } Complete the code for the line that calls the sum function. Write the sum function.
would someone kindly convert the following C code to java? thanks so much # include <stdio.h>...
would someone kindly convert the following C code to java? thanks so much # include <stdio.h> int main(void) { int changeOwed; int check; char invisibleChar; int count = 0; int numQ=0, numD=0, numN=0, numP=0; do{ printf("How much change is owed (in cents)?\n"); check = scanf("%d", &changeOwed); // returns 1 if the input is a number and returns 0 otherwise //Get's rid of any extra invisible characters if the input is a char/String do{ scanf("%c",&invisibleChar); }while(invisibleChar != '\n'); }while(check == 0...
why's is my csis.txt saving ? #include <stdio.h> FILE*fp; void calculateBMI(void); int main(void) {    fp...
why's is my csis.txt saving ? #include <stdio.h> FILE*fp; void calculateBMI(void); int main(void) {    fp = fopen("csis.txt", "w"); for (int i= 0; i<4; ++i){ calculateBMI(); } fclose(fp); return 0; } void calculateBMI(void){ double weight,height,bmi;    printf("Enetr your weight in pounds:\n\n"); fprintf(fp,"Enter your weight in pounds:\n\n"); scanf("%lf",&weight); printf("Enter height in inches:\n\n"); fprintf(fp,"Enter height in inches:\n\n"); scanf("%lf",&height); bmi=(703*weight)/(height*height);    if (bmi<18.5){ printf("You have a BMI of %.lf, and your weight status is underweight\n",bmi);    fprintf(fp,"You have a BMI of %.lf, and...
#include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]){ int fd1, fd2;...
#include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]){ int fd1, fd2; char buffer[100]; long int n1; if(((fd1 = open(argv[1], O_RDONLY)) == -1) || ((fd2 = open(argv[2], O_CREAT|O_WRONLY|O_TRUNC,0700)) == -1)){ perror("file problem "); exit(1); } while((n1=read(fd1, buffer, 512) > 0)) if(write(fd2, buffer, n1) != n1){ perror("writing problem "); exit(3); } // Case of an error exit from the loop if(n1 == -1){ perror("Reading problem "); exit(2); } close(fd2); exit(0); } There is an issue with this...
C CODE PLZ! All instructions are in sections of code #include <stdio.h> /* TODO: Define 3...
C CODE PLZ! All instructions are in sections of code #include <stdio.h> /* TODO: Define 3 functions input, gcd and lcm in such a way that the main function below compiles correctly and has the correct behavior. The input function prompts the user to enter a non-negative integer. If the user enters a negative integer, the function prints a "sorry" statement and prompts the user again. It keeps on prompting until the user enters a non-negative number. The input function...
Explain this code function by function in detail int menu() {   int choice;   do {     system("cls");...
Explain this code function by function in detail int menu() {   int choice;   do {     system("cls");     printf("1-Insurence Plan Subscription\n");     printf("2-Claim Processing\n");     printf("3-Accounts Information\n");     printf("4-Searching Functionalities\n");     printf("5-Exit\n");     scanf("%d", &choice);   } while (choice > 5 || choice < 1);   return choice; void subscribe() system("cls");   victims[userCount].id = userCount + 1;   printf("Enter age: ");   scanf("%d", &victims[userCount].age);   printf("\n\n%-25sHealth Insurence Plan\n\n", " ");   printf("-----------------------------------------------------------------------------------------------\n");   printf("|%-30s|%-20s|%-20s|%-20s|\n", " ", "Plan 120(RM)", "Plan 150(RM)", "Plan 200(RM)");   printf("-----------------------------------------------------------------------------------------------\n");   printf("|%-30s|%-20d|%-20d|%-20d|\n", "Monthly Premium", 120, 150, 200);   printf("|%-30s|%-20d|%-20d|%-20d|\n", "Annual Claim Limit", 120000,150000,200000);   printf("|%-30s|%-20d|%-20d|%-20d|\n",...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT