Add Two Numbers Using Function
C++
Easy
6 views
Problem Description
Create function that takes two numbers and returns their sum.
Real Life: Like a adding machine that does addition for you.
Step-by-Step Logic:
1. Create function with two parameters
2. Add both parameters
3. Return result
4. Call function from main and print result
Official Solution
int addNumbers(int a, int b) {
int sum = a + b;
return sum;
}
void function_q1_add() {
int num1 = 15;
int num2 = 25;
int result = addNumbers(num1, num2);
cout << "Sum of " << num1 << " and " << num2 << " is: " << result << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!