2_Questions_6_1_do_while-1

2_Questions_6_1_do_while-1 - n > 0 1 5 CIS 15AG...

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

View Full Document Right Arrow Icon
CIS 15AG Questions 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 True READ x, y WRITE x int x, y; printf("Enter x and y: "); scanf("%d %d", &x, &y); printf("Now x is %d", x ); x y x y Output 3 13 -10 False -10 x y x y Output 13 3 -10 False -10 x x < 35 Output 1 x x > 3 Output 100
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 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); printf("%d %d", c, x ); x y c x y Output 3 13 -10 False -10 x y c x y Output 13 3 -10 False -10 5 – n Output x n
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n &gt; 0 1 5 CIS 15AG Questions Chapter 6: Repetitions (do while) 5. Write a function for the following flow chart. If the above algorithm was executed on the data shown, what value would the variable m contain upon completion ? Also, for each data set, count the iterations. 3 r m % n n r m n r True gcdEuclid(m, n) return m int gcdEuclid( int m, int n ) { int r; return m; } m n r r 24 18 -10 False -10 m n r r 21 15 -10 False -10 m n r r 18 24 -10 False -10 CIS 15AG Questions Chapter 6: Repetitions (do while) 6. Write a function that uses a dowhile loop to read and validate an hour. A valid hour number is 0, 1, 2, 23. Then call it from main(). #include&lt;stdio.h&gt; int main(void) { int hour; printf(&quot;hour = %d&quot;, hour); return 0; } /* ====================================== */ Get and validate an hour. Pre: nothing Post: valid hour: 0, 1, 2, , 23 */ 4...
View Full Document

Page1 / 4

2_Questions_6_1_do_while-1 - n &amp;amp;gt; 0 1 5 CIS 15AG...

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

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