Compute the cyclomatic complexity of the following sample codes: Sample Code 1:
/*
* C Program to Print Diamond Pattern
*/
#include <stdio.h>
int main()
{
int number, i, k, count = 1;
printf("Enter number of rows\n"); scanf("%d", &number);
count = number - 1;
for (k = 1; k <= number; k++)
{
for (i = 1; i <= count; i++) printf(" ");
count--;
for (i = 1; i <= 2 * k - 1; i++) printf("*");
printf("\n");
}
count = 1;
for (k = 1; k <= number - 1; k++)
{
for (i = 1; i <= count; i++) printf(" ");
count++;
for (i = 1 ; i <= 2 *(number - k)- 1; i++) printf("*");
printf("\n");
}
return 0;
}
Sample code 2:
# Python program to # print Diamond shape
# Function to print # Diamond shape
def Diamond(rows): n = 0
for i in range(1, rows + 1): # loop to print spaces
for j in range (1, (rows - i) + 1):
print(end = " ")
# loop to print star while n != (2 * i - 1):
print("*", end = "") n = n + 1
n = 0
# line break print()
k = 1
n = 1
for i in range(1, rows): # loop to print spaces
for j in range (1, k + 1): print(end = " ")
k = k + 1
# loop to print star
while n <= (2 * (rows - i) - 1):
print("*", end = "") n = n + 1
n = 1 print()
# Driver Code
# number of rows input rows = 5 Diamond(rows)
Also, create a GUI tool for Cyclomatic complexity using any language. Run the above sample code on your tool to validate your answer.
Comments
Leave a comment