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 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...
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 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...
Thank You Define the gcd of three integers a, b, c as the largest common divisor...
Thank You Define the gcd of three integers a, b, c as the largest common divisor of a, b, c, and denote it by (a, b, c). Show that (a, b, c) = ((a, b), c) and that (a, b, c) can be expressed as a linear combination of a, b, c.
The language is MATLAB Write a function that will generate three random integers, each in the...
The language is MATLAB Write a function that will generate three random integers, each in the inclusive range from 10 to 80. It will then return a string consisting of the three integers joined together, and also a character vector consisting of the three integers joined together. For example, if the random integers are 11, 29, and 76, the string that is returned will be "112976" and the character vector that is returned will be '112976'. I'm really confused on...
Write a function that takes three integers, n, a and b and a filename and writes...
Write a function that takes three integers, n, a and b and a filename and writes to the file a list with n random integers between a and b. And then write a function that can read the files as generated above and return the values. language: python
Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer called removeItem.
Java programming:Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer called removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (Note that after deleting the element, the array size is reduced by 1.) You may assume that the array is unsorted.Now re-do this exercise and name it ExInsertionSort....
8.Let a and b be integers and d a positive integer. (a) Prove that if d...
8.Let a and b be integers and d a positive integer. (a) Prove that if d divides a and d divides b, then d divides both a + b and a − b. (b) Is the converse of the above true? If so, prove it. If not, give a specific example of a, b, d showing that the converse is false. 9. Let a, b, c, m, n be integers. Prove that if a divides each of b and c,...
An integer n is said to be Pythagorean if there exist two nonzero integers x and...
An integer n is said to be Pythagorean if there exist two nonzero integers x and y such that x2 + y2 = n2 . Present an O(n) time algorithm to check if a given integer n is Pythagorean or not. Assume that you can nd the square root of any number in O(1) time.
For all integers n > 2, show that the number of integer partitions of n in...
For all integers n > 2, show that the number of integer partitions of n in which each part is greater than one is given by p(n)-p(n-1), where p(n) is the number of integer partitions of n.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT