Below is the pseudo-code for a TRICKY program:
0 program TRICKY
1 var1, var2, var3 : integer
2 begin
3 read(var2)
4 read(var1)
5 while var2 < 10 loop
6 var3 = var2 + var1
7 var2 = 4
8 var1 = var2 + 1
9 print(var3)
10 if var1 = 5 then
11 print(var1)
12 else
13 print(var1+1)
14 endif
15 var2 = var2 + 1
16 endloop
17 print(“Wow – that was tricky!”)
18 print(“But the answer is...”)
19 print(var2+var1)
20 end program TRICKY
Which of the following statements about the TRICKY program MOST correctly describes any
control flow anomalies in it?
Select ONE option.
The programmers have designed three versions of a function that finds the largest number among three integers: findMax1, findMax2 and findMax3. One of them must be chosen for the next release. The codes look as follows:
int findMax1(int n1, int n2, int n3) {
int max;
if (n1 >= n2 && n1 >= n3)
max = n1;
if (n2 >= n1 && n2 >= n3)
max = n2;
if (n3 >= n1 && n3 >= n2)
max = n3;
return max;
}
int findMax2(int n1, int n2, int n3) {
int max;
if (n1 >= n2 && n1 >= n3)
max = n1;
else if (n2 >= n1 && n2 >= n3)
max = n2;
else
max = n3;
return max;
}
int findMax3(int n1, int n2, int n3) {
int max;
if (n1 >= n2) {
if (n1 >= n3)
max = n1;
else
max = n3;
} else {
if (n2 >= n3)
max = n2;
else
max = n3;
}
return max;
}
You were asked to select the one with the lowest cyclomatic complexity. Which ONE should you choose?
Select ONE option.