In: Computer Science
Code in C
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.
Ex: If the input is:
7 15 3
the output is:
largest: 15 smallest: 3
Your program must define and call the following two functions.
The LargestNumber function should return the largest number of the
three input values. The SmallestNumber function should return the
smallest number of the three input values.
int LargestNumber(int userNum1, int userNum2, int userNum3)
int SmallestNumber(int userNum1, int userNum2, int userNum3)
File: ls.c
#include <stdio.h>
int LargestNumber(int userNum1, int userNum2, int userNum3);
int SmallestNumber(int userNum1, int userNum2, int userNum3);
int main()
{
int a,b,c, largest, smallest;//declaring
variable
//Accepting input from user
printf("\nEnter First Number:");
scanf("%d",&a);
printf("\nEnter Second Number:");
scanf("%d",&b);
printf("\nEnter Third Number:");
scanf("%d",&c);
//calling function
largest = LargestNumber(a,b,c);
smallest = SmallestNumber(a,b,c);
//display output
printf("\nThe Largest Number: %d", largest);
printf("\nThe Smallest Number: %d", smallest);
return(0);
}
//function for finding largest number
int LargestNumber(int userNum1, int userNum2, int userNum3)
{
if(userNum1 > userNum2 && userNum1 >
userNum3)
return userNum1;
else if(userNum2 > userNum3)
return userNum2;
else
return userNum3;
}
//function for finding smallest number
int SmallestNumber(int userNum1, int userNum2, int userNum3)
{
if(userNum1 < userNum2 && userNum1 <
userNum3)
return userNum1;
else if(userNum2 < userNum3)
return userNum2;
else
return userNum3;
}
Screen: