C++ Exercises: Check the largest number among three given integers
C++ Basic Algorithm: Exercise-18 with Solution
Write a C++ program to check the largest number among three given integers.
Sample Solution:
C++ Code :
#include <iostream>
using namespace std;
int test(int x, int y, int z)
{
int result = max(x, max(y, z));
return result;
}
int main()
{
cout << test(1,2,3) << endl;
cout << test(1,3,2) << endl;
cout << test(1,1,1) << endl;
cout << test(1,2,2) << endl;
return 0;
}
Sample Output:
3 3 1 2
Pictorial Presentation:
Flowchart:
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C++ program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string.
Next: Write a C++ program to check which number nearest to the value 100 among two given integers. Return 0 if the two numbers are equal.
What is the difficulty level of this exercise?