Question: In C++ Write a function that adds all the odd numbers from 1 to n. For example addOdd(9) would return 1+3+5+7+9 = 25. Note if
In C++
Write a function that adds all the odd numbers from 1 to n. For example addOdd(9) would return 1+3+5+7+9 = 25. Note if n is even then addOdd(n) will be the same as addOdd(n-1).
Prototype: int addOdd(int n);
The driver used to test your code is below:
int main(){ int n; cin >> n; cout << "n = " << n << endl; cout << "addOdd(" << n << ") = " << addOdd(n) << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
