This preview shows pages 1–3. Sign up to view the full content.
CIS 15AG
Answers Chapter 6:
Repetitions
(while)
7. Code the following flow chart fragment, then predict the output when x = 3, y = 13, and
x = 13, y = 3.
8. Predict the output.
char x = 'A';
while
( x < 'E' )
printf("%c\n", x++ );
char x = 'A';
while
( x < 'E' )
printf("%c\n", ++x );
1
x
≥
y
True
READ x, y
WRITE x
x
x  y
int x, y;
printf("Enter x and y: ");
scanf("%d %d", &x, &y);
while
( x >= y )
x = x – y;
printf("Now x is %d", x );
x
y
x
≥
y
Output
3
13
False
3
No iterations!
10
False
10
x
y
x
≥
y
Output
13
3
True
10
True
7
True
4
True
1
False
1
4 iterations!
Output
A
B
C
D
Output
B
C
D
E
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document CIS 15AG
Answers Chapter 6:
Repetitions
(while)
9. Write a function for the following flow chart. All parameters are
int
. The first two are input
parameters and the last two are output parameters.
Deskcheck the algorithm for x = 17, y = 5, then for x = 5, y = 17. What problem does this
algorithm solve?
2
True
x
x  y
q
q + 1
q
0
x
≥
guess(x, y, q, r)
return
r
x
void quess( int
x,
int
y,
int *q,
int *r )
{
*q = 0;
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.
 Spring '10
 Staff
 Computer Programming

Click to edit the document details