4)[findTheMinimum .c ] In your main program, ask the user for 3 numbers. If they
ID: 3733039 • Letter: 4
Question
4)[findTheMinimum.c] In your main program, ask the user for 3 numbers. If they are all -1, your loop will end.
Otherwise pass those 3 numbers to a function, calculateMin, which will return the minimum of the 3 numbers. calculateMin will look like this
int calculateMin( int num1, int num2, int num3);
So your output should look like this:
Enter 3 numbers: 1 2 3
The minimum number is 1
Enter 3 numbers: -10 1 11
The minimum number is -10
Enter 3 numbers: -1 -1 -1
You found 2 minimum numbers.
Again, all the prints should be in the main, not the module.
Explanation / Answer
#include<stdio.h>
#include<string.h>
int calculateMin(int num1,int num2,int num3)
{
return (num1<(num2<num3)?num2:num3)?num1:(num2<num3)?num2:num3;
}
int main()
{
int i,num1,num2,num3,data;
printf("Enter 3 numbers: ");
scanf("%d", &num1);
scanf("%d", &num2);
scanf("%d", &num3);
if(num1==-1)
{
if(num1==num2&&num2 == num3)
printf("You found 2 minimum numbers.");
}
else
printf("The minimum number is %d",calculateMin(num1,num2,num3));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.