Name: ____________________

 

 

CS 0007 – Lab 2

 

Simple Looping

 

For this lab, write a program to compute 3 sums based on user input. The user will input a number (let’s call it N) and you should tell the user:

  1. The sum from 1 to N
  2. The sum of the even numbers from 1 to N
  3. The sum of the odd numbers from 1 to N

 

The purpose of this assignment is to get familiar with looping and to use the shortcut operators like += and ++ wherever possible.

 

Example

 

Enter a positive integer:

30

The sum is 465

The sum of the evens is 240

The sum of the odds is 225

 

Hints

 

 

 

 

 

When you’re done, have Rasoul check you off here: __________ and you can go.