| |

VerySource

 Forgot password?
 Register
Search
Author: 丁欠欠

How to edit this in C ++? ? ?

[Copy link]

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-22 22:15:01
| Show all posts
Yes, the upstairs is right, I just saw this problem, the OddSum function should be written at least like this:

int OddSum (int m, int n)
{
// This is actually a summation problem of arithmetic sequence
int Begin, End, Sum = 0;

Begin = (m% 2 == 0? M + 1: m); // If m is an odd number, the starting item is m, otherwise m + 1
End = (n% 2 == 0? N-1: n); // If n is odd, the ending item is n, otherwise it is n-1

return (Begin + End) * ((End-Begin) / 2 + 1) / 2; // Sum formula of arithmetic sequence
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list