2_Questions_6_1_do_while-1

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

Info icon This 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 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
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 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
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n > 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 do…while loop to read and validate an hour. A valid hour number is 0, 1, 2, … 23. Then call it from main(). #include<stdio.h> int main(void) { int hour; printf("hour = %d", hour); return 0; } /* ====================================== */ Get and validate an hour. Pre: nothing Post: valid hour: 0, 1, 2, …, 23 */ 4...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern