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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!