{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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.
Image of page 1

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

View Full Document Right 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
Image of page 2
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 user’s input; if you reject the user’s 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern