2_Questions_5_2_if-1

2_Questions_5_2_if-1 - CIS 15AG 1 Questions Chapter 5:...

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

View Full Document Right Arrow Icon
CIS 15AG Questions Chapter 5: Selection – Making Decisions (the if statement) 11. Predict the output: if (a > 0 && b > 0) printf("**"); printf("Done\n"); if (a > 0) printf("*"); if (b > 0) printf("*"); printf("Done\n"); 12. What happens when a semicolon is inadvertently inserted as it is shown below? if (a > 0 && b > 0) ; printf("**"); printf("Done\n"); 13. Predict the output: if (a > 0 && b > 0) printf("**"); printf("Done\n"); if (a > 0 && b > 0) { printf("**"); printf("Done\n"); } 1 a b Output 5 5 5 -5 -5 5 -5 -5 a b Output 5 5 5 -5 -5 5 -5 -5 a b Output 5 5 5 -5 -5 5 -5 -5 a b Output 5 5 5 -5 -5 5 -5 -5 a b Output 5 5 5 -5 -5 5 -5 -5
Background image of page 1

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

View Full DocumentRight Arrow Icon
CIS 15AG Questions Chapter 5: Selection – Making Decisions (the if statement) 14. Predict the output: if (a > b) a = b; printf("%d %d", a, b); if (a > b) { a = b; printf("%d %d", a, b); } 15. Predict the output: if (a > b) { hold = a; a = b; b = hold } printf("%d %d", a, b); 16. Predict the output: sum = 0; if (a > 0) sum += a; if (b > 0) sum += b; if (c > 0) sum += c; if (d > 0) sum += d; printf("%d", sum); 2 a b Output 10 5 5 5 5 10 a b Output 10 5 5 5 5 10 a b Output 10 5 5 5 5 10 a b c d Output 10 10 10 10 -10 10 10 10 10 -10 10 10 10 10 -10 10 10 10 10 -10 -10 -10 10 10 -10 10 -10 10 -10 10 10 -10 -10 -10 -10 10 -10 -10 10 -10 -10 -10 -10 -10
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

2_Questions_5_2_if-1 - CIS 15AG 1 Questions Chapter 5:...

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

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