Sums of the Natural, Odd, and Even Numbers up to N

Easy

Read an integer N and print three lines: sum of natural numbers = 55, sum of odd numbers = 25, sum of even numbers = 30, where the three values are the sums of 1 to N, of the odd numbers in that range, and of the even numbers in that range. Use one for loop from 1 to N with three long accumulators. N must be between 1 and 60000 so that the sums fit in a 32-bit long; otherwise print N must be between 1 and 60000 and return 1. If N cannot be read, print invalid input and return 1.

Success Criteria

Your code must pass 7 test case(s) to complete this exercise. 3 hint(s) are available if you need help.

How did you find this exercise?

Your rating helps us improve the content.

Sign in to track your progress

You can work on exercises as a guest, but sign in to track your progress and save your submissions.

This platform is built by its community

Every lesson, project, and tool on HelloC++ is funded by sponsors. Join them and help shape what we build next.

Become a Patron