Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this task, you will create a program which reads in 3 numbers and prints out

ID: 670566 • Letter: I

Question

In this task, you will create a program which reads in 3 numbers and prints out the maximum of those. You should accept the three numbers through the command line only. If there is not a valid number of command line arguments you must display an error and terminate.

To determine the maximum of three numbers we will require you to create two functions: max2 and max3. The function max2 takes in two integers and returns the larger of the two. The function max3 takes in three integers and returns the larger of the three.

For this task we require that max3 use the function max2 to determine the maximum of three numbers. You cannot use any conditionals inside of max3but you can use anything in max2.

Here is how your program should be compiled and executed

Here is another run of your program

Explanation / Answer

Please find below the code of max3.c program:

#include <stdio.h>

int max2(int,int);
int max3(int,int,int);

int main(void) {
  
int a,b,c;

if ( (scanf("%i",&a) == 1 ) && (scanf("%i",&b) == 1 ) && (scanf("%i",&c) == 1 ) ){
printf("The maximum number entered was %i ",max3(a,b,c));
   return 0;
}
else{
printf("Invalid numbers entered ");
return 0;  
}

}

int max2(int a2,int b2){
double m=a2;
if (m < b2) m = b2;
return m;
};
int max3(int a1,int b1,int c1){
return max2(max2(a1,b1),c1);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote