Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming Problem. The program below is named prog have to convert it using the functions ask of the programing problem. # include # include

C programming Problem. The program below is named "prog" have to convert it using the functions ask of the programing problem.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

# include # include int main (void) char menuoption; int intx, inty, answeri, count, n, fact; double doublex, doubley, answerd; //prompt user /menu printf (" nOperation printf ("Add printf ("Subtract printf ("Multiply printf ("Divide printf ("Remainder printf ("Squared printf ("Square Root printf ("Factorial printf ("Is even printf "Greater integer G "); printf ("Less integer printf ("Exit progranm Menu Option ") A ") S ") M ") D ") TIn") F ") E ") X ") printf ("Please enter a menu option from the table above: ") scanf("%c", &menuoption); switch (menuoption) //addition case'a case'A': printf ("Please enter the first number: ") scanf("%lf", &doublex); printf ("Please enter the second number: "); scanf ("1f", &doubley) answerd- doublex doubleyi printf ("Answer8.21f", answerd); break; //subtraction case's case' S': printf ("Please enter the first numbe scanf("%lf", &doublex); printf ("Please enter the second number:"); scanf("%lf", &doubley); answerd- doublex-doubley; printf ("Answer.21f", answerd) break; //multiplication case 'm': case'M' printf ("Please enter the first number:") scanf ("%1f", &doublex); printf ("Please enter the second number:"); scanf("%lf", &doubley); answerd- doublex doubley; printf ("Answer - 8.2f ", answerd); break; //division case 'd case'D' printf("Please enter the first number:" scanf("%lf", &doublex); printf ("Please enter the second number:"); scanf("%lf", &doubley); if (doubley0) //checking if denominator is zero printf("invalid, cannot divide by zero "); else answerd- doublex doubley; printf "Answer -8.2f ", answerd); break; //remainder case 'r': case'R': printf ("Please enter the first number:"); scanf("%d", &intx); printf ("Please enter the second number:"); scanf ("%d", &inty) ; answe ri= intx % nty; printf( "Answer- %d ", answe ri); break; //squared case 'v case'V': printf ("Please enter the number to be squared: "); scanf ("%1f", &doublex) ; answerd-doublex*doublex; printf ("Answer-.21f", answerd); break; //square root case 't': case'T': printf ("Please enter the number to take the square root of:") scanf("%lf", &doublex); if (doublex 0) for (count= n ; count>= 1; count- fact fact *count; printf ("Factorial- %d", fact ); else printf ("The factorial of 0 is 1.") break; //even case 'e': case'E': printf ("Please enter the first number:") scanf("%d", &intx); answe ri- intx % 2; if (answeri--0) printf ("The number is even. " else printf ("The number is not even. "); break; //greater integer case 'g: case'G': printf("Please enter the first number:" scanf("%lf", &doublex); answeri- ceil (doublex) printf( "Answer- %d", answe ri); break; //lesser integer case '1': case'L' printf ("Please enter the first number:"); scanf ("%d", &doublex) ; answeri- floor (doublex) printf ("Answer -d", answeri); break; //exit progran IyI return 0; break; case 'x': case'X' //improper input default: printf ("Input not recognized. "); while (1) return 0 Change the code in the posted for the program posted in the same module named "prog" as follows and submit as program 6: Create functions and function prototypes to replace each of the calculator actions. Prototype each function above main and write the function (definition) below main. - The input by the user and output statement of each calculation should stay in main and not be moved to a function except the output for function "iseven" which should be done in the function. Each function will accept the value(s) supplied by the user as parameters and return the result in a return statement (not a printf statement except for "iseven") - The result returned by each function should be outputted by a printf statement in main. Create a function named display that contains: menu display statements, the user prompt to select an option, user input. This function should have no parameters and should return a character as the option chosen by the user. The functions required are: char display (void); double add (double, double); double sub (double, double); double mult double, double); double div(double, double) int remain (int, int); double square (double); double saroot (double) ; int factorial (int) void iseen (int) int greaterint (double) int lesserint (double) # include # include int main (void) char menuoption; int intx, inty, answeri, count, n, fact; double doublex, doubley, answerd; //prompt user /menu printf (" nOperation printf ("Add printf ("Subtract printf ("Multiply printf ("Divide printf ("Remainder printf ("Squared printf ("Square Root printf ("Factorial printf ("Is even printf "Greater integer G "); printf ("Less integer printf ("Exit progranm Menu Option ") A ") S ") M ") D ") TIn") F ") E ") X ") printf ("Please enter a menu option from the table above: ") scanf("%c", &menuoption); switch (menuoption) //addition case'a case'A': printf ("Please enter the first number: ") scanf("%lf", &doublex); printf ("Please enter the second number: "); scanf ("1f", &doubley) answerd- doublex doubleyi printf ("Answer8.21f", answerd); break; //subtraction case's case' S': printf ("Please enter the first numbe scanf("%lf", &doublex); printf ("Please enter the second number:"); scanf("%lf", &doubley); answerd- doublex-doubley; printf ("Answer.21f", answerd) break; //multiplication case 'm': case'M' printf ("Please enter the first number:") scanf ("%1f", &doublex); printf ("Please enter the second number:"); scanf("%lf", &doubley); answerd- doublex doubley; printf ("Answer - 8.2f ", answerd); break; //division case 'd case'D' printf("Please enter the first number:" scanf("%lf", &doublex); printf ("Please enter the second number:"); scanf("%lf", &doubley); if (doubley0) //checking if denominator is zero printf("invalid, cannot divide by zero "); else answerd- doublex doubley; printf "Answer -8.2f ", answerd); break; //remainder case 'r': case'R': printf ("Please enter the first number:"); scanf("%d", &intx); printf ("Please enter the second number:"); scanf ("%d", &inty) ; answe ri= intx % nty; printf( "Answer- %d ", answe ri); break; //squared case 'v case'V': printf ("Please enter the number to be squared: "); scanf ("%1f", &doublex) ; answerd-doublex*doublex; printf ("Answer-.21f", answerd); break; //square root case 't': case'T': printf ("Please enter the number to take the square root of:") scanf("%lf", &doublex); if (doublex 0) for (count= n ; count>= 1; count- fact fact *count; printf ("Factorial- %d", fact ); else printf ("The factorial of 0 is 1.") break; //even case 'e': case'E': printf ("Please enter the first number:") scanf("%d", &intx); answe ri- intx % 2; if (answeri--0) printf ("The number is even. " else printf ("The number is not even. "); break; //greater integer case 'g: case'G': printf("Please enter the first number:" scanf("%lf", &doublex); answeri- ceil (doublex) printf( "Answer- %d", answe ri); break; //lesser integer case '1': case'L' printf ("Please enter the first number:"); scanf ("%d", &doublex) ; answeri- floor (doublex) printf ("Answer -d", answeri); break; //exit progran IyI return 0; break; case 'x': case'X' //improper input default: printf ("Input not recognized. "); while (1) return 0 Change the code in the posted for the program posted in the same module named "prog" as follows and submit as program 6: Create functions and function prototypes to replace each of the calculator actions. Prototype each function above main and write the function (definition) below main. - The input by the user and output statement of each calculation should stay in main and not be moved to a function except the output for function "iseven" which should be done in the function. Each function will accept the value(s) supplied by the user as parameters and return the result in a return statement (not a printf statement except for "iseven") - The result returned by each function should be outputted by a printf statement in main. Create a function named display that contains: menu display statements, the user prompt to select an option, user input. This function should have no parameters and should return a character as the option chosen by the user. The functions required are: char display (void); double add (double, double); double sub (double, double); double mult double, double); double div(double, double) int remain (int, int); double square (double); double saroot (double) ; int factorial (int) void iseen (int) int greaterint (double) int lesserint (double)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions