Pregram-6-Programm 1- Change the code in the posted for the program posted in th
ID: 3731606 • Letter: P
Question
Pregram-6-Programm 1- 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:Explanation / Answer
PROGRAM
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
// Create display function arithmetic menu
char display()
{
char ch;
printf(" ARITHEMATIC MENU ");
printf("================== ");
printf(" A. Addition");
printf(" S. Subtract");
printf(" M. Multiplication");
printf(" D. Division");
printf(" R. Remainder");
printf(" Q. Square");
printf(" U. Square Root");
printf(" F. Factorial");
printf(" E. is Event");
printf(" G. Greater Int");
printf(" L. Lesser Int");
printf(" X. EXIT");
printf(" ================== ");
printf(" Enter Your Choice: ");
scanf("%c",&ch);
return ch;
}
// Implement add() function
double add(double x,double y)
{
return x+y; // return result
}
// Implemnet sub() function
double sub(double x,double y)
{
return x-y; // return result
}
// Implement mult() function
double mult(double x,double y)
{
return x*y;// return result
}
// Implement divide() function
double divide(double x,double y)
{
return x/y; // return result
}
// Implement remain() fucntion
int remain(int x,int y)
{
return x%y; // return result
}
// Implement square() function
double square(double x)
{
return x*x; // return result
}
// Implement Sqroot() function
double sqroot(double x)
{
return sqrt(x); // return result
}
// Implement factorial() function using recursion
int factorial(int x)
{
if(x==0) return 1;
else
return x*factorial(x-1); // return result
}
// Implement iseven() fucntion
void iseven(int x)
{
if(x%2==0)
printf(" %d is Even ",x);
else
printf(" %d is Not Even ",x);
}
// Implemnet greaeterint() function
int greaterint(double x)
{
return ceil(x); // return result
}
// Implement lesserint() function
int lesserint(double x)
{
return floor(x); // return result
}
int main()
{
// Declare variable such as double, integer and character for choice
char ch;
double a,b,res;
int x,y,z;
while(1) // Create infinity while loop until exit(0)
{
fflush(stdin); // clear input memory using fflush(stdin)
ch=display(); // call display() function and receive character value
switch(ch) // create switch case and accessing character value
{
case 'a':
case 'A': {
printf(" Enter a Value: "); scanf("%lf",&a);
printf(" Enter b Value: "); scanf("%lf",&b);
res=add(a,b); // call add() function
printf(" Addition of a and b value is: %.2lf ",res);
break;}
case 's':
case 'S': {
printf(" Enter a Value: "); scanf("%lf",&a);
printf(" Enter b Value: "); scanf("%lf",&b);
res=sub(a,b); // call sub() function
printf(" Subtraction of a and b value is: %.2lf ",res);
break;}
case 'm':
case 'M': {
printf(" Enter a Value: "); scanf("%lf",&a);
printf(" Enter b Value: "); scanf("%lf",&b);
res=mult(a,b); // call mult() function
printf(" Multiplication of a and b value is: %.2lf ",res);
break;}
case 'd':
case 'D': {
printf(" Enter a Value: "); scanf("%lf",&a);
printf(" Enter b Value: "); scanf("%lf",&b);
res=divide(a,b); // call divide() function
printf(" Division of a and b value is: %.2lf ",res);
break;}
case 'r':
case 'R': {
printf(" Enter Integer a Value: "); scanf("%d",&x);
printf(" Enter Integer b Value: "); scanf("%d",&y);
z=remain(x,y); // call remain() function
printf(" Remainder of a and b value is: %d ",z);
break;}
case 'q':
case 'Q': {
printf(" Enter a Value: "); scanf("%lf",&a);
res=square(a); // call square() function
printf(" Square of a value: %.2lf",res);
break;}
case 'e':
case 'E': {
printf(" Enter Integer Number: "); scanf("%d",&x);
iseven(x); // call iseven() function
break;}
case 'f':
case 'F': {
printf(" Enter Integer Number: "); scanf("%d",&x);
z=factorial(x); // call factorial() function
printf(" %d Factorial is: %d",x,z);
break;}
case 'u':
case 'U': {
printf(" Enter a Value: "); scanf("%lf",&a);
res=sqroot(a); // call sqroot() function
printf(" Square Root %.2lf is %.2lf",a,res);
break;}
case 'g':
case 'G': {
printf(" Enter a Value: "); scanf("%lf",&a);
z=greaterint(a); // call greaterint() function
printf(" Greatest Integer is: %d",z);
break;}
case 'l':
case 'L': {
printf(" Enter a Value: "); scanf("%lf",&a);
z=lesserint(a); // call lesserint() function
printf(" Lesser Integer is: %d",z);
break;}
case 'x':
case 'X': exit(0); break;
default: printf(" Invalid Choice. Try Again "); break;
}
}
return 0;
}
OUTPUT
ARITHEMATIC MENU
==================
A. Addition
S. Subtract
M. Multiplication
D. Division
R. Remainder
Q. Square
U. Square Root
F. Factorial
E. is Event
G. Greater Int
L. Lesser Int
X. EXIT
==================
Enter Your Choice: a
Enter a Value: 43.5
Enter b Value: 23.4
Addition of a and b value is: 66.90
ARITHEMATIC MENU
==================
A. Addition
S. Subtract
M. Multiplication
D. Division
R. Remainder
Q. Square
U. Square Root
F. Factorial
E. is Event
G. Greater Int
L. Lesser Int
X. EXIT
==================
Enter Your Choice: q
Enter a Value: 3
Square of a value: 9.00
ARITHEMATIC MENU
==================
A. Addition
S. Subtract
M. Multiplication
D. Division
R. Remainder
Q. Square
U. Square Root
F. Factorial
E. is Event
G. Greater Int
L. Lesser Int
X. EXIT
==================
Enter Your Choice: u
Enter a Value: 4
Square Root 4.00 is 2.00
ARITHEMATIC MENU
==================
A. Addition
S. Subtract
M. Multiplication
D. Division
R. Remainder
Q. Square
U. Square Root
F. Factorial
E. is Event
G. Greater Int
L. Lesser Int
X. EXIT
==================
Enter Your Choice: g
Enter a Value: 543.24524
Greatest Integer is: 544
ARITHEMATIC MENU
==================
A. Addition
S. Subtract
M. Multiplication
D. Division
R. Remainder
Q. Square
U. Square Root
F. Factorial
E. is Event
G. Greater Int
L. Lesser Int
X. EXIT
==================
Enter Your Choice: l
Enter a Value: 6424.234
Lesser Integer is: 6424
ARITHEMATIC MENU
==================
A. Addition
S. Subtract
M. Multiplication
D. Division
R. Remainder
Q. Square
U. Square Root
F. Factorial
E. is Event
G. Greater Int
L. Lesser Int
X. EXIT
==================
Enter Your Choice: x