In: Computer Science
in Coral Simulator
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
The function LargestNumber should return the largest number of the three input values. The function SmallestNumber should return the smallest number of the three input values.
Code to Copy:
Function LargestNumber(integer num1, integer num2, integer num3) returns integer largestNum
// Define a function LargestNumber() to find largest among 3
// numbers. It accepts three numbers and returns largest number.
if num1>num2 and num1>num3
largestNum=num1
elseif num3>num1 and num3>num2
largestNum=num3
else
largestNum=num2
Function SmallestNumber(integer num1, integer num2, integer num3) returns integer smallestNum
// Define a function SmallestNumber() to find largest among 3
// numbers. It accepts three numbers and returns smallest number.
if
num1
smallestNum=num1 elseif
num3
smallestNum=num3
else
smallestNum=num2 Function Main()
returns nothing //
Define a Main() function. //
Define three integer variables.
integer num1
integer num2
integer num3
//Prompt the user to get 3 integer numbers.
num1=Get next input
num2=Get next input
num3=Get next input //
Display the largest number and call LargestNumber() Put
"largest: " to output Put
LargestNumber(num1,num2,num3) to output //
Display the smallest number and call smallestNumber() Put
"smallest: " to output Put
SmallestNumber(num1,num2,num3) to output