0
$\begingroup$
int i=0,j;

while(i<=n)
{
 while(j<=(i+1)){ 
   a=a*a;
    j++;
  }
i++;

This question was in my homework and we have to calculate the frequency count of the code above. I am having difficulty understanding how the code will execute and how many times will the loops execute. I know the inner loop is dependent on 'i', otherwise I'm lost.

$\endgroup$
3
  • $\begingroup$ Do you reset $j$ before the second while loop? If not, then the second loop will take only one operation, since $j$ would already be incremented a big nch of times $\endgroup$ – nir shahar Mar 26 at 11:24
  • $\begingroup$ Is this typed exactly as its written, or are there possibly some errors in typing it? $\endgroup$ – awillia91 Mar 27 at 13:40
  • $\begingroup$ This how to question was given to me in my homework. I made no changes $\endgroup$ – Brishti Basu Mar 28 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.