1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ki77a [65]
3 years ago
13

How many iterations for each for-loop where max = 10 and incr = 3 a. for (int i = 0; i < max; i++) b. for (int i = 0; i <

max; i += 2) c. for (int i = 0; i < max; i += incr) d. for (int i = incr; i < max; i += incr) e. for (int i = max; i > 0; i--) f. for (int i = max; i < 0; i--) g. for (int i = 1; i < max; i *= incr) h. for (int i = 0; i < max; i *= incr)
Computers and Technology
1 answer:
LekaFEV [45]3 years ago
4 0

Explanation:

Answer to the following iterations are:

a)

In the following for-loop, the loop will starts from 0 and end at 9.

for example:

0 1 2 3 4 5 6 7 8 9

So, the loop will iterate 0-9, which means 10 times.

b)

In the following for-loop, the loop will starts from 0 and end at 8 but in the gap of 2 because of the increment of 2 in the variable "i".

for example:

0 2 4 6 8

So, the loop will iterate even times or 5 times, which means 0 2 4 6 8.

c)

In the following for-loop, the loop will starts from 0 and end at 9 but in the gap of 3  because of the increment of 3 in the variable "i" and the value is assign in the variable "incr" is 3.

for example:

0 3 6 9

So, the loop will iterate 4 times, which means 0 3 6 9.

d)

In the following for-loop, the loop will starts from 3 and end at 9 but in the gap of 3  because of the increment of 3 in the variable "i" and the value is assign in the variable "incr" is 3.

for example:

3 6 9

So, the loop will iterate 3 times, which means 3 6 9.

e)

In the following for-loop, the loop will starts from 10 and end at 1 which means reverse order.

for example:

10 9 8 7 6 5 4 3 2 1

So, the loop will iterate 10-1, which means 10 times in reverse order.

f)

In the following for-loop, the loop will not works because of the condition which is i is less than 0 but in the following code loop will starts from 3.

So, that's why loop will not iterate.

g)

In the following for-loop, the loop will starts from 1 and end at 9 but in the multiple of 3  because the variable "i" will multiply by the variable "incr" and the value is assign in the variable "incr" is 3.

for example:

1 3 9

So, the loop will iterate 3 times, which means 1 3 9.

h)

In the following for-loop, the loop is the infinite loop because of the condition which is i is less than max but and the loop will starts from 0 and goes on infinite times.

So, that's why it is the infinite loop.

You might be interested in
Are there any output differences between floats and doubles?
lana [24]

Explanation:

The precision in double values is twice as compared to float values.Hence double have smaller rounding errors as compared to float variables .A double is of 64 bits and float is of 32 bits usually hence floats have more rounding errors and on more number than doubles.Double has 15 decimal digits of precision and float has only 7 decimal digits for precision.

5 0
3 years ago
The use of multiple _______ is sometimes called using a search phrase.
zysi [14]
Hello, thank you for your question.

The answer to your question, "<span>The use of multiple _______ is sometimes called using a search phrase.," would be:

Keywords</span>
4 0
3 years ago
David bought 5.2 pounds of oranges for $1.20 per pound . how much did david spend ..............................................
Tcecarenko [31]

Answer:

David spent $6.24.

Explanation:

5.2 times 1.2

3 0
3 years ago
Paano nakatutulong ang teknolohiyang pangkomunikasyon sa pangangalap ng impormsyon
Makovka662 [10]

Answer:

Yes correct. Absolutely breathtaking. You should create poetry with your writing skills.

6 0
3 years ago
A ball is released from a 10 m high roof and bounces two thirds as high on each successive bounce. After traveling a total of 40
skelet666 [1.2K]

Answer:

Four times traveling 40,12345 mts

Explanation:

We can express this as a sum as follows

\sum_{i=1}^4(10\cdot  \frac{2}{3}^{i - 1} + 10\cdot  \frac{2}{3}^{i } ) = 3250/81=40.12345679

The first term is the dropping part and the second is the upward motion. this sums up to 40,12345 m after bouncing four times. As a program we could write using the while loop.

distance=0;

i:=0;

while distance<40 do

i:=i+1;

distance:=distance+ 10\cdot  \frac{2}{3}^{i - 1} + 10\cdot  \frac{2}{3}^{i };

end while;

Here the answer is in i and the closest distance traveled after reaching 40 is in the variable distance.

4 0
4 years ago
Other questions:
  • Which statement relating to a Works Cited page is NOT True?
    11·2 answers
  • A form of speech used by a speaker who is attempting to be witty and amusing is _________.
    13·2 answers
  • Life changing technology is easy to fall in love with. Describe a feature of a product that did it for you and highlight its ben
    13·1 answer
  • Which of the following is an example of a complex formula
    8·1 answer
  • What is the value of the average variable after the following code is executed? var sum = 0; var prices = [14, 10, 9, 12, 11, 14
    14·1 answer
  • I can't find the errors! Could anyone help me please?!
    5·1 answer
  • Which console was the first to use CD-ROM storage
    5·1 answer
  • How can you resize the program window?​
    5·2 answers
  • The largest group of Linux users is likely to be
    7·1 answer
  • Joe is examining the logs for his web server and discovers that a user sent input to a web application that contained the string
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!