Homework 09: Nested loops
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Wednesday, February 1
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw09
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: Section 5 (Nested loops & Stepwise refinement) from the Unit 3 notes, Note: You do not need to go through the full example in section 5.4 (stepwise refinement from the inside out) if you will be in class.
-
Write a program called
counting.c
that reads an integer \(n\) from the user, and then uses a nested loop to count from 1 up to 1, then from 1 up to 2, then from 1 up to 3, etc., and finally from 1 up to \(n\).Example of running your program:
roche@ubuntu$
./counting
Enter n:
5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Note: be careful not to print an extra space at the end of each line!