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

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.
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 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...
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....
The C function funsum below takes three arguments -- an integer val and two function pointers...
The C function funsum below takes three arguments -- an integer val and two function pointers to functions f and g, respectively. f and g both take an integer argument and return an integer result. The function funsum applies f to val, applies g to val, and returns the sum of the two results. Translate to RISC-V following RISC-V register conventions. Note that you do not know, nor do you need to know, what f and g do, nor do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT