Find Maximum Using Function
C++
Easy
4 views
Problem Description
Create function that takes two numbers and returns larger one.
Real Life: Like choosing bigger apple from two apples.
Step-by-Step Logic:
1. Function receives two numbers
2. Compare both numbers
3. Return whichever is larger
4. Print returned value
Official Solution
int findMaximum(int a, int b) {
if(a > b) {
return a;
} else {
return b;
}
}
void function_q3_maximum() {
int num1 = 45;
int num2 = 67;
int max = findMaximum(num1, num2);
cout << "Maximum is: " << max << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!