44.5k views
3 votes
write a program that takes in three integers and outputs the largest value. if the input integers are the same, output the integers' value.

User Azangru
by
6.8k points

1 Answer

6 votes

Answer:

#include <iostream>

int findLargest(int a, int b, int c) {

if (a == b && b == c) {

return a;

} else {

int largest = a;

if (b > largest) largest = b;

if (c > largest) largest = c;

return largest;

}

}

int main() {

int a, b, c;

std::cout << "Enter the first integer: ";

std::cin >> a;

std::cout << "Enter the second integer: ";

std::cin >> b;

std::cout << "Enter the third integer: ";

std::cin >> c;

int largest = findLargest(a, b, c);

std::cout << "The largest integer is: " << largest << std::endl;

return 0;

}

Step-by-step explanation:

The function findLargest takes in three integers a, b, and c. If all the integers are the same, it returns the integer. Otherwise, it compares the values of a, b, and c and returns the largest value. In the main function, the three integers are read from the user, and the result of findLargest is printed to the screen.

User Alagner
by
6.8k points