Lab06_sample - and 10 (you will need to validate the users...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPSC 101 Introduction to Algorithmic Processes Summer 2007 LAB 6 – Nested Loop 1. Write a program that uses a nested loop to generate the following layout of numbers. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 // File name: Lab06_01.cpp // Description: // Lab 06-1 // Author: Jaehyun Lim // Date: Monday, July 9, 2007 #include <iostream> using namespace std; int main() { for ( int i = 1; i < 10; i++) { for ( int j = 1; j <= i; j++) cout << i << " " ; cout << endl; } return 0; } 2. Modify your program from part 1 to generate the following pattern.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 // File name: Lab06_02.cpp // Description: // Lab 06-2 // Author: Jaehyun Lim // Date: Monday, July 9, 2007 #include <iostream> using namespace std; int main() { for ( int i = 1; i < 10; i++) { for ( int j = 1; j <= i; j++) cout << j << " " ; cout << endl; } return 0; } 3. Write a program that reads five integers from the keyboard. Each integer is between 1
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: and 10 (you will need to validate the users input; if you reject the users input, you must re-read the input until a valid quantity is entered). For each input, your program should print a line of dollar signs, of length x, where x is the integer value entered. Enter a number: 7 Sample $$$$$$$ Dialogue Enter a number: 12 Invalid input. Enter a number: 3 $$$ // File name: Lab06_03.cpp // Description: print a line of dollor signs of length x // Lab 06-3 // Author: Jaehyun Lim // Date: Monday, July 9, 2007 #include <iostream> using namespace std; int main() { int number; for ( int counter = 1; counter <= 5; counter++) { cout << "Enter a number: " ; cin >> number; while (number<1 || number>10) { cout << "Invalid input." << endl; cout << "Enter a number: " ; cin >> number; } for ( int i = 1; i <= number; i++) cout << "$" ; cout << endl; } return 0; }...
View Full Document

This note was uploaded on 07/14/2008 for the course CMPSC 101 taught by Professor Drobish,renee during the Summer '07 term at Pennsylvania State University, University Park.

Page1 / 3

Lab06_sample - and 10 (you will need to validate the users...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online