I am trying to calculate the Cyclomatic complexity for this code.
double power(int x,int y){
int exp;
double res;
if (y>0)
exp = y;
else
exp = -y; res=1;
while (exp!=0){
res *= x;
exp -= 1;
}
if (y<=0)
if(x==0)
abort;
else
return
1.0/res;
return
res;
}
using the 1st method V(G)= e–n+2 = 14 - 13 + 2 = 3
the 2nd method gives me a different result V(G) = P +1; where P is the number of predicate nodes V(G) = 4 + 1 = 5
Is this OK? or must be the same?