Anda di halaman 1dari 1

Step Count - Count no of program steps.

Comments are not evaluated so they are not considered as program step.

In while loop steps are equal to the number of times loop gets executed.

In for loop,steps are equal to number of times an expression is checked for condition.

A single expression is considered as a single step.Example a+f+r+w+w/q-d-f is one step.

step count method

1. int mean(int a[], size_t n)

2. {

3. int sum = 0; // 1 step * 1

4. for (int i = 0; i < n; i++) // 1 step * (N+1)

5. sum += a[i]; // 1 step * N

6. return sum; // 1 step * 1

7. }

Add up the steps: 1 + (N+1) + N + 1

Reduce: 2N + 3

Anda mungkin juga menyukai