Welcome Guest.

# Analyze the following number of execution times in the preface

Asked by: Frank James 23 views IT January 13, 2023

void delay ()

{uINT I, j;

for (i = 0; i <120; i ++)

for (j =0; j <150; j ++);

}

1. +3Votes  Simple, the outer cycle I circulate 120 times, and the inner cycle is 150 times, so the total cycle is

120*150 = 18000 (times)

2. +8Votes  If you are not wrong, it is 120 x 150 times

Answer: This principle is simple 360 Q &A.When I is 0, J is 0, and then J is added to 149.Then J clears zero, I can enter one, J is added from 0 to 149 under the condition of i = 1, J is cleared, and I enter one to 2, J is from 0-149.When I = 119, the outside cycle is over and all cycles ends.As for why, it is because of “++”.Variable ++ represents each execution of the cycle, the variable value +1
I finally add 120, because 0-119 is 120 (just as 1-120 is 120); SimilarSo when I = 119, the inner cycle (J) has been executed 120 x 150 = 18000 and the wrong (18,000) times.And because the inner cycle (i), there is no code in the outer circulation (j), 18,000 times are executed by empty sentences.
For another example: If the code is changed:
void delay ()
{UINT I, J;
for (n = 0; n <10; n ++)
For (i = 0; i <120; still short -term medical practitioner I ++)
for (j = 0; j <150; j ++);
}
Then the number of execution times at this time = 10 x 12 Forest photos of the number of torture between the torture is also 0 x 150 = 180,000 (180,000) times

from Jiangsu