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
Aleks04 [339]
3 years ago
6

Bob and Alice are solving practice problems for CSE 2320. They look at this code: for(i = 1; i <= N; i = (i*2)+17 ) for(k = i

+1; k <= i+N; k = k+1) // notice i in i+1 and i+N printf("B"); Alice says the loops are dependent. Bob says they are not dependent. Who is correct? ____________ What do you think? Are they dependent or not dependent? They are __________
Engineering
2 answers:
MissTica3 years ago
8 0

Answer:

Alice is correct.

The loop are dependent.

Explanation:

for(i = 1; i <= N; i = (i*2)+17 )

for(k = i+1; k <= i+N; k = k+1) // notice i in i+1 and i+N

printf("B")

This is a nested for-loop.

After the first for-loop opening, there is no block of statement to be executed rather a for-loop is called again. And the second for-loop uses the value of i from the first for-loop. The value of N is both called from outside the loop.

So, the second for-loop depend on the first for loop to get the value of i. For clarity purpose, code indentation or use of curly brace is advised.

ZanzabumX [31]3 years ago
4 0
<h2>Answer:</h2>

Alice is correct

They are dependent

<h2>Explanation:</h2><h2></h2>

<em>The code snippet can be re-written as follows;</em>

<em></em>

for(i = 1; i <= N; i = (i*2)+17 )

  for(k = i+1; k <= i+N; k = k+1)

<em>Which can also be re-written as;</em>

<em></em>

for(i = 1; i <= N; i = (i*2)+17 ) {

   for(k = i+1; k <= i+N; k = k+1){

   }

}

In many programming languages, curly brackets are used for grouping blocks of codes. For a for loop, while loop, if statement and other related control structures, the lines of statement(s) inside their curly brackets are executed when they are encountered. In the case where any of these control statements is written without curly brackets, the next line of code (and that only) following it belongs to its block.  

Consequential from the foregoing, at each of cycles of the <em>outer</em> <em>for loop</em> in the first code snippet above, the <em>inner for loop </em>will be executed. In other words, the inner for loop belongs to the block of the outer for loop though there is no curly bracket included. This also means that once a control statement has only a single line of code to be executed or to be a part of its block, curly brackets are not required. Therefore, the two versions of code snippets written above are identical and equivalent.

With the aforementioned, it is easy to say and see that the Alice is correct that the loops are dependent on each other.

You might be interested in
Im passed due someone help meeeeeee
vovangra [49]

Answer:

how are supposed to help when you can't do anything?

8 0
3 years ago
Read 2 more answers
When the Moon is in the position shown, how would the Moon look to an observer on the North Pole?
kirill115 [55]

Answer:

cant see the moon sorry dude

5 0
3 years ago
Showing or hiding records in a database is called “filtering.”<br> True<br> False
agasfer [191]

Answer:

TRUE

Explanation:

4 0
2 years ago
Read 2 more answers
What is the measurement below?
Bess [88]

Explanation:

इसिसिसिसैस्स्स्स्स्स्स्स्स्स्सूस्सोस्स्स्स्स्स

8 0
3 years ago
Why must air tanks be drained​
Jobisdone [24]
Water can freeze in cold weather and cause brake failure.
7 0
3 years ago
Other questions:
  • Water flovs in a pipe of diameter 150 mm. The velocity of the water is measured at a certain spot which reflects the average flo
    13·1 answer
  • Determine the direct runoff and streamflow given the following unit hydrograph. The rainfall is collected at 4-hour intervals an
    14·1 answer
  • When choosing a respirator for your job, you must conduct a _____ test.
    15·1 answer
  • Two gases—neon and air—are expanded from P1 to P2 in a closed-system polytropic process with n = 1.2. _____ produces more work w
    7·1 answer
  • An extruder barrel has a diameter of 4.22 inches and a length of 75 inches. The screw rotates at 65 revolutions per minute. The
    14·1 answer
  • which systems engineering support discipline has the goal to ensure that support considerations are an integral part of the syst
    14·1 answer
  • Please look at the attachments and help me with these questions
    7·1 answer
  • Please help I am give brainiliest
    9·1 answer
  • An agricultural manager requires
    12·1 answer
  • Describe the risks associated with their working environment (such as the tools, materials and equipment that they use, spillage
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!