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 DocumentRight 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 &lt;iostream&gt; using namespace std; int main() { int len; cout &lt;&lt; &quot;Enter a number: &quot;; cin &gt;&gt; len; if (len &gt; 0) { int i = 0; do { int j = i+1; while (j &lt; len) { cout &lt;&lt; ' '; j++; } cout &lt;&lt; &quot;#&quot; &lt;&lt; endl; i++; } while (i &lt; len); } } 5. The switch segment that replaces the if statement is as follows, switch (month) { case 6: cout &lt;&lt; &quot;summer solstice&quot;; break; case 12: cout &lt;&lt; &quot;winter solstice&quot;; break; case 3: cout &lt;&lt; &quot;equinox&quot;; break; case 9: cout &lt;&lt; &quot;equinox&quot;; break; default: cout &lt;&lt; &quot;nothing special&quot;; }...
View Full Document

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