Write a program that does the following Includes a function that computes and re
ID: 3566480 • Letter: W
Question
Write a program that does the following Includes a function that computes and returns two values.
The function should accept 2 values - x and y.
The function should accept 3 parameters for returning values.
One should return the minimum value of x and y. One should return the maximum value of x and y One should return the average of x and y. Includes a second function which tests the first function by calling it with three values and printing the result. It should accept two parameters- x and y. It should call the first function to determine the minimum, maximum, and average values It should print x and y and the three computed values. Have the main() function call the second function for 6 different values of x and y that demonstrates correct operation for various cases.
Explanation / Answer
#include <stdio.h>
#include <string.h>
void first(int x, int y, int* minimum, int* maximum, int* average){
*minimum = (x <= y) ? x : y;
*maximum = (x >= y) ? x : y;
*average = (x + y)/2;
}
void second(int x, int y){
int minimum,maximum,average;
first(x,y,&minimum,&maximum,&average);
printf("Minimum = %d, Maximum = %d, Average = %d ",minimum,maximum,average);
}
main()
{
int i;
for(i=0;i<6;i++){
printf("Please enter two numbers : ");
int x,y;
scanf("%d %d",&x,&y);
printf("%d %d ",x,y);
second(x,y);
}
}
//Sample output
Executing the program....
$demo
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.