{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

3_Answers_6_1_do_while-1

3_Answers_6_1_do_while-1 - CIS 15AG Answers Chapter 6...

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

View Full Document Right Arrow Icon
CIS 15AG Answers Chapter 6: Repetitions (do … while) 1. Code the following flow chart fragment, then predict the output when x = 3, y = 13, and x = 13, y = 3. 2. Predict the output. x = 1; do x *= 2; while ( x < 35 ); printf("%d\n", x ); x = 100; do x /= 2; while ( x > 3 ); printf("%d\n", x ); 1 x x - y x y True READ x, y WRITE x int x, y; printf("Enter x and y: "); scanf("%d %d", &x, &y); do x = x – y; while ( x >= y ); printf("Now x is %d", x ); x y x y Output 3 13 -10 False -10 1 iteration -10 False -10 x y x y Output 13 3 10 True 7 True 4 True 1 False 1 4 iterations x x < 35 Output 1 2 True 4 True 8 True 16 True 32 True 64 False 64 6 iterations x x > 3 Output 100 50 True 25 True 12 True 6 True 3 False 3 5 iterations
Background image of page 1

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

View Full Document Right Arrow Icon
CIS 15AG Answers Chapter 6: Repetitions (do … while) 3. Code the following flow chart fragment, then predict the output when x = 3, y = 13, and x = 13, y = 3. 4. Predict the output. n = 5; x = 1; do { printf("%d. %d\n", 5 – n, x ); x *= 2; n--; }while ( n > 0 ); 2 x x - y x y True READ x, y WRITE c, x c c + 1 c 0 int x, y; printf("Enter x and y: "); scanf("%d %d", &x, &y); do { x = x – y; c = c + 1; }while ( x >= y ); printf("%d %d", c, x ); x y c x y Output
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.

{[ snackBarMessage ]}