2_Questions_5_2_if-1

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

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

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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/02/2011 for the course CIS 15BG taught by Professor Staff during the Spring '10 term at DeAnza College.

### 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
Ask a homework question - tutors are online