hw - for loop for the inner loop and a do-while loops...

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

View Full Document Right Arrow Icon
Homework 2—Computer Science 31 Ahmad El-Arabi 1. The program segment will output the following: endlendl grendel 2. The program prints out, depending on what number ( len ) the user has inputted, the “#” symbol after len-1 spaces, and repeats this with one less space on each next line until we print the “#” symbol on the last line. 3. The program changed to use a while loop instead of a for loop for the inner loop, looks like the following: #include <iostream> using namespace std; int main() { int len; cout << "Enter a number: "; cin >> len; for (int i = 0; i < len; i++) { int j = i+1; while (j < len) { cout << ' '; j++; } cout << "#" << endl; } } 4. The program changed to use a while loop instead of a
Background image of page 1

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

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for loop for the inner loop and a do-while loops instead of the outer for loop, looks like the following: #include <iostream> using namespace std; int main() { int len; cout << "Enter a number: "; cin >> len; if (len > 0) { int i = 0; do { int j = i+1; while (j < len) { cout << ' '; j++; } cout << "#" << endl; i++; } while (i < len); } } 5. The switch segment that replaces the if statement is as follows, switch (month) { case 6: cout << "summer solstice"; break; case 12: cout << "winter solstice"; break; case 3: cout << "equinox"; break; case 9: cout << "equinox"; break; default: cout << "nothing special"; }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

hw - for loop for the inner loop and a do-while loops...

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

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