Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started