15.9k views
0 votes
Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. If the input is 7 15 3, the output is: largest: 15 smallest: 3 Your program should define and call two functions: Function LargestNumber(integer num1, integer num2, integer num3) returns integer largestNum Function SmallestNumber(integer num1, integer num2, integer num3) returns integer smallestNum

2 Answers

1 vote

Final answer:

The program must have two functions, LargestNumber and SmallestNumber, which return the largest and smallest integers among the three inputs respectively.

Step-by-step explanation:

The student's question requires a program wherein the input is three integers and the output is the largest and smallest of those three values. The program should include two functions: LargestNumber and SmallestNumber. Here is how you can write the program in a generic way:

Function LargestNumber(integer num1, integer num2, integer num3) returns integer {
if (num1 >= num2 && num1 >= num3) {
return num1;
} else if (num2 >= num1 && num2 >= num3) {
return num2;
} else {
return num3;
}
}

Function SmallestNumber(integer num1, integer num2, integer num3) returns integer {
if (num1 <= num2 && num1 <= num3) {
return num1;
} else if (num2 <= num1 && num2 <= num3) {
return num2;
} else {
return num3;
}
}

This code will find the largest and smallest numbers among three integers that are given as inputs and print them out accordingly.

User GarethOwen
by
6.6k points
7 votes

Answer:

int SmallestNumber(int num1, int num2, int num3){

int smallest;

if (num1 >num2){

smallest=num2;

}

else {

smallest=num1;

}

if(smallest <num3){

smallest=num3;

}

}

int LargestNumber(int num1, int num2, int num3){

int largest;

if (num1 <num2){

largest=num2;

}

else {

largest=num1;

}

if(largest>num3){

largest=num3;

}

}

void main(){

int num1,num2,num3;

printf("enter values");

scanf("%d%d%d",&num1,&num2,&num3);

int smallest=SmallestNumber(num1,num2,num3);

int largest=LargestNumber(num1,num2,num3);

}

Step-by-step explanation:

we are comparing first two numbers and finding largest among those. After getting largest comparing that with remaining if it is greater then it will be largest of three. Same logic applicable to smallest also

User Vlad Turak
by
6.1k points