Lexington High School Mathematics Math Dept. Front Page  | Student Links  | Family Links 
Introduction to C++, Kevin Kelly Kelly Front Page  | C++ Course Guide | C++ Assignments | C++ Info

Assignment 20: Sum of odd numbers

due Thursday 4/4
(last assignment of quarter)

For this assignment you have to write two short programs, 20A and 20B. Hand in everything at once (two programs, two runs), stapled together.

Program 20A: Write a program that adds the first thousand odd numbers: 1+3+5+7+9+11+... Compare the answer you get with other students' answers.

Program 20B: If you used a for statement in Program 20A, write a second version of the program that uses either while or do...while, instead. If you didn't use for in Program 21A, write a second version of the program that does use for.

Extension

For 10 pts.: Write an additional program that displays the sum of the first 1000 odd numbers, the sum of the first 2000 odd numbers, the sum of the first 3000 odd numbers, the sum of the first 4000 odd numbers, and so on up through the sum of the first 20000 odd numbers.