Question: C exercise - Define a menu function dispMenu (defined below) which will let the user select which exercise to demo. The user can quit with

C exercise -

Define a menu function dispMenu (defined below) which will let the user select which exercise to demo. The user can quit with q or Q. The user can stay within a particular exercises function until they quit with a sentinel code that you choose.

// returns menu choice 1 to n. Define n choices for now. You can change n to whatever you need it to be. int dispMenu();

(

Switch case

Define a menu function dispMenu (defined below) which will let the user select which exercise to demo. The user can quit with q or Q. The user can stay within a particular exercises function until they quit with a sentinel code that you choose.

// returns menu choice 1 to n. Define n choices for now. You can change n to whatever you need it to be. int dispMenu();

with comment blocks

Function 1

#include #include

double roundNumber(double x);

int main() { double a; int n; printf(" Enter a number to get its round off value: "); scanf("%lf", &a);

printf(" Original number is %.2lf, Rounded number is %.0lf. ",a,roundNumber(a)); }

double roundNumber(double x) { double y; int n;

for (n = 1; n <= 5; n++) {

y = floor(x + .5);

}return y; }

Function 2

#include #include

double roundToInteger(double number) { return floor(number + .5); } double roundToTenths(double number) { return floor(number * 10 + .5) / 10; } double roundToHundreths(double number) { return floor(number * 100 + .5) / 100; } double roundToThousandths(double number) { return floor(number * 1000 + .5) / 1000; } int main() { double x; printf("Enter number to round: "); scanf("%lf", &x); printf(" Number: %lf Rounded to integer: %.0lf Rounded to nearest tenth: %.1lf Rounded to nearest hundredth: %.2lf Rounded to nearest thousandth: %.3lf ", x, roundToInteger(x), roundToTenths(x), roundToHundreths(x),roundToThousandths(x));

return 0; } Function 3

#include

int even(int a);

int main(){ int n,t;

while(1){ for(int i=0;i<=t;i++){ printf(" enter the number:"); scanf("%d",&n); even(n); // Function is called here } return (0); } }

int even(int a){ if(a%2==0){ printf("%d is even number. ",a); } else { printf ("%d is odd number. ",a); } } Function 4

#include #include

void printsquare(int side,char c) { for(int i=0;i

}

int main() { void printsquare(int,char); // header of the function ( declaration ) int x ; char c; printf("Enter side and fill character: "); // take side and character from user scanf("%d %c",&x,&c); printsquare(x,c); }

Function 5

//function function3-5.23 #include #include double clock(int hr, int mn, int sec);

int main() { int h, m, s; double c1, c2, d; while(1){ printf("Enter first time,hours,minutes,seconds:"); scanf("%d,%d,%d", &h, &m, &s); c1 = clock(h, m, s); printf("Enter second time,hours,minutes,seconds:"); scanf("%d,%d,%d", &h, &m, &s); c2 = clock(h, m, s); d = fabs(c1 - c2); printf(" Time difference is %.2lf seconds ", d); return 0; }}

double clock(int hr, int mn, int sec) { double second = (hr * 3600) + (mn * 60) + sec; return second; } Function 6

#include int ftoc(int num); int ctof(int num); int ftoc(int num) { printf("\t\t%6.1f", (5.0 / 9.0) * (num - 32.0)); return 0; } int ctof(int num) { printf("\t\t%6.1f ", (9.0 * num) / 5.0 + 32); return 0; }

int main() { printf("Temperature Conversions "); int num; printf("\tNUMBER\t\tCELSIUS(FtoC)\tFAHRENHEIT(CtoF) "); for(num=0;num<=100;num++) { printf("\t%d ",num); printf("\t%d",ftoc(num)); printf("\t%d",ctof(num)); } }

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!