Computer Science, asked by kanishk702, 9 months ago

Determine the cyclomatic complexity for the following code: Accept year

if(year mod 4=0 and year mod 100!=0) or(year mod 400 =0)

print year is leap

else

print year is not leap

end if.

Answers

Answered by Anonymous
5

Answer:

Cyclomatic complexity of a code section is the quantitative measure of the number of linearly independent paths in it. It is a software metric used to indicate the complexity of a program. It is computed using the Control Flow Graph of the program. The nodes in the graph indicate the smallest group of commands of a program, and a directed edge in it connects the two nodes i.e. if second command might immediately follow the first command.

For example, if source code contains no control flow statement then its cyclomatic complexity will be 1 and source code contains a single path in it. Similarly, if the source code contains one if condition then cyclomatic complexity will be 2 because there will be two paths one for true and the other for false.

Mathematically, for a structured program, the directed graph inside control flow is the edge joining two basic blocks of the program as control may pass from first to second.

So, cyclomatic complexity M would be defined as,

Answered by brainlysme13
0

The cyclomatic complexity of the given statement is 2.

Cyclomatic Complexity:

  • Cyclomatic complexity of a code section is the quantitative measure of the number of linearly independent paths in it.
  • It is a software metric used to indicate the complexity of a program.
  • It is computed using the Control Flow Graph of the program.
  • The nodes in the graph indicate the smallest group of commands of a program, and a directed edge in it connects the two nodes i.e. if second command might immediately follow the first command.

How to figure out cyclomatic complexity:

  • Cyclomatic complexity can be measured by checking the branching in the flow of control of a program, generally in the presence of a control flow statement.
  • For instance, the source code will have a single path and a cyclomatic complexity of 1 if there are no control flow statements.
  • Similar to this, if the source code contains a single if statement, then the number of pathways will be two, with one leading to true and the other to false.

Hence, in the given program code, the flow of statement deviates on the basis of two conditions: when the "if" condition results out to be TRUE, and when the "if" condition results out to be FALSE.

Therefore, the cyclomatic complexity is 2.

Read more on Brainly.in

1. https://brainly.in/question/16580346

2. https://brainly.in/question/21006270

#SPJ2

Similar questions