Problem 5 - a = b++; cout <<...

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

View Full Document Right Arrow Icon
ECOR1606 – Problem Solving and Computers Page 1 of 2 Department of Systems and Computer Engineering Carleton University P ROGRAM O UTPUTS Background information This lab is intended to be done on paper and help enable you to evaluate your understanding of basic programming. For the following programs, determine what the output display will be. For example, the code: #include <iostream.h> void main(void) { int a = 5; int b = 3; cout << a/b << endl; } the output display will be 1 Note you can easily check your answer by running the program Program #1 #include <iostream.h> void main(void) { int a = 0; int b = 1; while ( (a != 0) && (b !=0) ) { cout << a++ << endl; cout << ++b << endl; } } Program #2 #include <iostream.h> void main(void) { int a = 0; int b = 1; while (a < 6) {
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: a = b++; cout &lt;&lt; &quot;a = &quot; &lt;&lt; a &lt;&lt; endl; b = ++a; cout &lt;&lt; &quot;b = &quot; &lt;&lt; b &lt;&lt; endl; } cout &lt;&lt; &quot;a = &quot; &lt;&lt; a &lt;&lt; endl; cout &lt;&lt; &quot;b = &quot; &lt;&lt; b &lt;&lt; endl; } ECOR1606 Problem Solving and Computers Page 2 of 2 Department of Systems and Computer Engineering Carleton University Program #3 #include &lt;iostream.h&gt; void main(void) { int a = 10, b; while (a &gt; 5) { for (b = 9; b &gt; 0; b = b - 2) { a = a - b/3; cout &lt;&lt; &quot;a = &quot; &lt;&lt; a &lt;&lt; endl; cout &lt;&lt; &quot;b = &quot; &lt;&lt; b &lt;&lt; endl; } a++; } cout &lt;&lt; &quot;a = &quot; &lt;&lt; a &lt;&lt; endl; cout &lt;&lt; &quot;b = &quot; &lt;&lt; b &lt;&lt; endl; } Program #4 #include &lt;iostream.h&gt; void main(void) { int x = 1; double y; do { cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; endl; for (y = 0; y &lt; x; y = y + 2) { cout &lt;&lt; &quot;y = &quot; &lt;&lt; y &lt;&lt; endl; } x = x + 2; } while (y &lt; 5); cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; endl; cout &lt;&lt; &quot;y = &quot; &lt;&lt; y &lt;&lt; endl; }...
View Full Document

Page1 / 2

Problem 5 - a = b++; cout &amp;amp;lt;&amp;amp;lt;...

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