Explaination for question no 2

Find the Complexity of the given snippet.

   void function(int n) 
   { 
     int count = 0; 

     for (int i=0; i<n; i++) 
     for (int j=i; j< i*i; j++) 
         if (j%i == 0) 
         { 
            for (int k=0; k<j; k++) 
                 printf("*"); 
          } 
    } 

Ans= O(n^5)

@7nishit
Consider the comments in the following function.

void function(int n)
{
int count = 0;

// executes n times 
for (int i=0; i<n; i++) 

    // executes O(n*n) times. 
    for (int j=i; j< i*i; j++) 
        if (j%i == 0) 
        { 
            // executes j times = O(n*n) times 
            for (int k=0; k<j; k++) 
                printf("*"); 
        } 

}
Therefor time Complexity of the above function O(n^5)

Kindly explain the significance of i&lt, j&lt and k&lt as it’s not there in the question, but you have mentioned it in your code.

which code are you referring to?

void function(int n) { int count = 0; for (int i=0; i<n; i++) for (int j=i; j< ii; j++) if (j%i == 0) { for (int k=0; k<j; k++) printf(""); } } … This is the code given in the question…And i am comparing it with the code given in the reply of yours.

It is just the same…just comments have been added.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.