Consider three software items: Program-X, Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown below Program-X: Control Flow Diagram of Program-Y sumcal (int maxint, int value)
{
int result=0, i=0;
if (value <0)
{
Value = -value;
}
while ( (i
Consider three software items: Program-X, Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown below Program-X: Control Flow Diagram of Program-Y sumcal (int maxint, int value) { int result=0, i=0; if (value <0) { Value = -value; } while ( (i<value) AND (result <= maxint) ) { i=i+1; result = result + 1; } if (result <= maxint) { print (result) ; } else { Printf(“large”); } printf(“end of program”); } Control Flow Diagram of Program-Z The values of McCabe’s Cyclomatic complexity of Program-X, Program-Y, and Program-Z respectively are Correct Answer 4, 4, 7
Concept:
Cyclomatic complexity is a source code complexity measurement that is being correlated to a number of coding errors.
Formula:
Cyclomatic complexity = e – n + 2p
Where, e = number of edges
n = number of nodes
p = number of nodes that have exit points
Also, cyclomatic complexity = number of predicates + 1
Or, cyclomatic complexity = number of regions
Explanation:
Program X contains three predicates i.e. three conditional statement i.e. 3
So, cylomatic complexity = 3 + 1 = 4
Program Y: this contains 4 regions.
So, cyclomatic complexity = 4
Program Z: Program Z contains both X and Y. Combining both, it contains 6 predicates .
So, cyclomatic complexity = 6 + 1 = 7