Problem 5

# Problem 5 - a = b cout<<"a ="<< a<<...

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

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) {

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a = b++; cout << "a = " << a << endl; b = ++a; cout << "b = " << b << endl; } cout << "a = " << a << endl; cout << "b = " << b << endl; } ECOR1606 – Problem Solving and Computers Page 2 of 2 Department of Systems and Computer Engineering Carleton University Program #3 #include <iostream.h> void main(void) { int a = 10, b; while (a > 5) { for (b = 9; b > 0; b = b - 2) { a = a - b/3; cout << "a = " << a << endl; cout << "b = " << b << endl; } a++; } cout << "a = " << a << endl; cout << "b = " << b << endl; } Program #4 #include <iostream.h> void main(void) { int x = 1; double y; do { cout << "x = " << x << endl; for (y = 0; y < x; y = y + 2) { cout << "y = " << y << endl; } x = x + 2; } while (y < 5); cout << "x = " << x << endl; cout << "y = " << y << endl; }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Problem 5 - a = b cout<<"a ="<< a<<...

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

View Full Document
Ask a homework question - tutors are online