7CCSMASE
Tutorial 3
1. Draw the control flow graph for the following program:
public int kcl(int x, int y){ int a;
int b;
while(𝑦 ≤ 10){
a = x*y; b = y-x; y++;
}
return a; }
2. Consider the following simple program (in no particular language) to find the smallest prime factor of a number:
smallest(int p) /* precondition p > 1 */ {
int q = 2;
while(p mod q > 0 AND q < sqrt(p) )
q := q+1
;
if (p mod q = 0)
then
print(q,''is the smallest factor'') else
print(p, ``is prime'')
;
}
• Draw the control flow graph for this program.