Homework 08: For loop
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Monday, January 30
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw08
and submit using the204sub
command. - This is an electronic homework and you do not need to print out anything to turn in during class.
Assignment
- Required reading: Sections 3 (Loop shortcuts) and 4 (Odds & ends) from the Unit 3 notes.
-
Write a program called
gaussfor.c
that reads an integer \(n\) from the user, and then uses afor
loop to add up the numbers from 1 to \(n\) and print out the sum.(Note: this is the same program that you wrote for homework 6, except using a for loop instead of a while loop.
Example of running your program:
roche@ubuntu$
./gaussfor
Enter n:
100
The sum of numbers from 1 up to 100 is 5050