# Tutorial_4 - Q1 If s is a compound statement and e1 e2 and...

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

Q1 . If s is a compound statement, and e1, e2, and e3 are expressions, then what is the difference between the program fragment: for (e1; e2; e3) s; and the fragment: e1; while (e2) { s; e3; } There is no difference in the output, only difference using the loop, the first one is using “for” loop and second one is using “while” loop. Q2. What is wrong with the following program: int main() { const double PI; int n; PI = 3.14159265358979; n = 22; } The PI has to be initialized earlier, in this there is no value for PI, here is the correction const double PI= 3.14159265358979; int n; n = 22;

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

View Full Document
Q3 Describe the output from this program: int main() { for (int i = 0; i < 8; i++) if (i%2 == 0) cout << i + 1 << "\t"; else if (i%3 == 0) cout << i*i << "\t"; else if (i%5 == 0) cout << 2*i - 1 << "\t"; else cout << i << "\t"; } i Process Output 1 0 i+1 = 0+1 1 2 1 i = 1 1 3 2 i + 1 = 2+1 3 4 3 i * i = 3*3 9 5 4 i+1 = 4+1 5 6 5 2 * i -1 =2*5-1 9 7 6 i + 1 = 6+1 7 8 7 i = 7 7 Hence the output will be 1 1 3 9 5 9 77
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

Tutorial_4 - Q1 If s is a compound statement and e1 e2 and...

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

View Full Document
Ask a homework question - tutors are online