SI 204 Spring 2017 / HWs


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 hw06 and submit using the 204sub command.
  • This is an electronic homework and you do not need to print out anything to turn in during class.

Assignment

  1. Required reading: Sections 1 (The idea of a loop) and 2 (While loop examples) from the Unit 3 notes.
  2. Write a program called gauss.c that reads an integer \(n\) from the user, and then uses a while loop 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$ ./gauss
    Enter n: 5
    The sum of numbers from 1 up to 5 is 15
    roche@ubuntu$ ./gauss
    Enter n: 100
    The sum of numbers from 1 up to 100 is 5050