Question

In: Computer Science

A function the largest integer among three integers.

Write a function, which accept three integer values as arguments find the largest of three and then return the largest value to main program. Write a main program which will call the function by passing three integer values and print the value returned by the function.?

Solutions

Expert Solution

The largest() function is tested in the main function below

 

 

#include<iostream>

using namespace std;

int largest(int first, int second, int third){

int max = first;

if(second>first && second>third){

max = second;

}

else if(third>first && third>second){

max = third;

}

return max;

}

//Testing largest function

 

int main(){

int first, second, third;

cout<<"Enter the first integer\n";

cin>>first;

cout<<"Enter the second integer\n";

cin>>second;

cout<<"Enter the third integer\n";

cin>>third;

cout<<"The largest integer is:  "<<largest(first, second, third)<<endl;

}

 


 

int largest(int first, int second, int third){

int max = first;

if(second>first && second>third){

max = second;

}

else if(third>first && third>second){

max = third;

}

return max;

}

 

Related Solutions

Write a function intLog of type Integer -> Integer that returns the exponent of the largest...
Write a function intLog of type Integer -> Integer that returns the exponent of the largest power of 2 less than its integer argument. This needs to be a haskell function
In C++ The greatest common divisor (GCD) of two integers in the largest integer that evenly...
In C++ The greatest common divisor (GCD) of two integers in the largest integer that evenly divides each of the numbers. Write a function called GCD that has a void return type, and accepts 3 parameters (first two by value, third by reference). The function should find the greatest common divisor of the first two numbers, and have the result as its OUTGOING value. Write a main function that asks the users for two integers, and uses your function to...
The greatest common divisor of two integers x and y is the largest positive integer that...
The greatest common divisor of two integers x and y is the largest positive integer that evenly divides both. For example, gcd(12,6)=6, gcd(21,14)=7, gcd(31,10)=1, gcd(55,25)=5 Recall that the gcd of two integers is gcd(a,0) = a gcd(a,b) = gcd(b, a%b) Create int gcd(int x, int y). Assume that the two integers are zero or positive. Write the code as a pure function. Put it in a file gcd.c. Of course, you will need to test it. The function Φ(n) counts...
7. Let m be a fixed positive integer. (a) Prove that no two among the integers...
7. Let m be a fixed positive integer. (a) Prove that no two among the integers 0, 1, 2, . . . , m − 1 are congruent to each other modulo m. (b) Prove that every integer is congruent modulo m to one of 0, 1, 2, . . . , m − 1.
Design a function called middle_value, that takes 3 integers, and returns the integer with the middle...
Design a function called middle_value, that takes 3 integers, and returns the integer with the middle value. If there is a tie, any of the possible middle values can be returned. Example: middle_value(1, 2, 8) -> 2 middle_value(9, 7, 7) -> 7 middle_value(3, 3, 3) -> 3 Design a function called combine_strings that takes two phrases and appends the longer string onto the back of the shorter one with no space between the two phrases joined. Example: If the phrases...
in coral write a program whose inputs are three integers, and whose output is the largest...
in coral write a program whose inputs are three integers, and whose output is the largest of the three values. Ex: If the input is 7 15 3, the output is: 15
Write a function named “compileStats” that has 4 parameters: a vector of integers, an integer representing...
Write a function named “compileStats” that has 4 parameters: a vector of integers, an integer representing the smallest value contained in the vector, an integer representing the largest value contained in the vector, and a double that represents the average of the values in the vector. The compileStats function will not “return” a value, it will set the Pass By Reference parameters to the correct values (smallest, largest, and average). Use the following main function in driver1b.cpp as a starting...
Write a Scheme function that takes two integers and returns the list of all integer numbers...
Write a Scheme function that takes two integers and returns the list of all integer numbers between these two integers (inclusively) in increasing order. (numbers 10 20) (10 11 12 13 14 15 16 17 18 19 20) Please explain every step.
Write a function convert_date that takes an integer as a parameter and returns three integer values...
Write a function convert_date that takes an integer as a parameter and returns three integer values representing the input converted into days, month and year (see the function docstring). Write a program named t03.py that tests the function by asking the user to enter a number and displaying the output day, month and year. Save the function in a PyDev library module named functions.py A sample run for t03.py: Enter a date in the format MMDDYYYY: 05272017 The output will...
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.
 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT