0 votes 0 votes How many times will the loop execute? What is the general expression in terms of 'n'? for( i=1; i<=n; i=i*3) { for( j=i; j<=n; j++) { printf ( "ravi"); } } Programming in C programming-in-c + – rishabhgupta12 asked Jul 19, 2018 rishabhgupta12 545 views answer comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments Anand. commented Jul 19, 2018 reply Follow Share it should be then $n \times \left \lceil \log _{3} n \right \rceil$ 0 votes 0 votes rishabhgupta12 commented Jul 19, 2018 reply Follow Share For n=3 "ravi" print 4 times .In your answer, "ravi" only prints 3 times. 0 votes 0 votes Shubham Shukla 6 commented Jul 19, 2018 reply Follow Share @rishab check the answer.. 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes ...check the answer Shubham Shukla 6 answered Jul 19, 2018 Shubham Shukla 6 comment Share Follow See 1 comment See all 1 1 comment reply rishabhgupta12 commented Jul 19, 2018 reply Follow Share Thank you. The answer is correct. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes n*logn. (base is 3) aambazinga answered Jul 19, 2018 aambazinga comment Share Follow See 1 comment See all 1 1 comment reply rishabhgupta12 commented Jul 19, 2018 reply Follow Share If I put n=3 in the nested loop the "ravi" will print 4 times. I want to know that can we derive any general formula to calculate how many times "ravi" print by putting the value of 'n' in the formula. n*log n(base 3) showing the wrong answer. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes first loop executes log3n times and for each and every instance of first loop second loop executes n times. so total nlog3n times the given loop executes imnitish answered Jul 19, 2018 imnitish comment Share Follow See all 0 reply Please log in or register to add a comment.