I want to write a function which will sum up odd numbers between N and M (int). N and M are parameters of function. anyone here to help?
thanks in advance.
( in C++ | I'm using Microsoft Visual Studio 2010)
First you need to check the parity of N and M to determine which odd number to start and end.
Then you can do the calculation either by Sum of Arithmetic Sequence Equation, or continuously adding in a loop.
well, I didn't get what you said.
there I meant that - let's say I've entered from keyboard ---- N=10 and M=15. so I want function to sum up numbers, which are odd between(also equal to N and M) 10 and 15. 10<x<15 . so they are 11 + 13 + 15 ..
so program should show me 39.
I couldn't write a body of that function, couldn't think a way
Well, what I told you is pretty much the pseudocode.
Since it's a rather simple 2-step function, I don't know what to tell you further without solving the problem for you.