Homework 06: While statement
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Wednesday, January 25
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw06and submit using the204subcommand. - This is an electronic homework and you do not need to print out anything to turn in during class.
Assignment
- Required reading: Sections 1 (The idea of a loop) and 2 (While loop examples) from the Unit 3 notes.
-
Write a program called
gauss.cthat reads an integer \(n\) from the user, and then uses awhileloop to add up the numbers from 1 to \(n\) and print out the sum.For example, if \(n=5\), then the result would be \(1+2+3+4+5\), which comes out to 15.
Example of running your program:
roche@ubuntu$./gaussEnter n:5The sum of numbers from 1 up to 5 is 15roche@ubuntu$./gaussEnter n:100The sum of numbers from 1 up to 100 is 5050