182k views
23 votes
Which for loop will iterate 100 times? Group of answer choices for (i = 0; i < 99; i++) for (i = 1; i < 99; i++) for (i = 0; i < 100; i++) for (i = 1; i < 100; i++)

User Cowsay
by
3.0k points

2 Answers

10 votes

Answer:

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

Step-by-step explanation:

User Acctman
by
3.4k points
5 votes

Answer:

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

Step-by-step explanation:

Required:

Which will iterate 100 times.

Analysing the loops one after the other


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

This loop begins at 0; i.e i = 0

and ends at 98; i.e. i<99

From 0 to 98 is 99; i.e. 98 - 0 + 1 = 99

Hence, this loop will iterate in 99 times


for (i = 1; i < 99; i++)

This loop begins at 1; i.e i = 1

and ends at 98; i.e. i<98

From 1 to 98 is 98; i.e. 98 - 1 + 1 = 98

Hence, this loop will iterate in 98 times


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

This loop begins at 0; i.e i = 0

and ends at 99; i.e. i<100

From 0 to 99 is 100; i.e. 99 - 0 + 1 = 100

Hence, this loop will iterate in 100 times


for (i = 1; i < 100; i++)

This loop begins at 1; i.e i = 1

and ends at 99; i.e. i<100

From 1 to 99 is 99; i.e. 99 - 1 + 1 = 99

Hence, this loop will iterate in 99 times

User Oleksandr Samsonov
by
3.1k points