0 votes 0 votes Consider the following code What is the output printed by the above code in terms of n? How it is coming b?? Programming in C programming output + – Shubhanshu asked Sep 24, 2017 Shubhanshu 753 views answer comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments Warlock lord commented Sep 25, 2017 reply Follow Share I'm getting (n)(2n-1) 0 votes 0 votes Shubhanshu commented Sep 25, 2017 reply Follow Share how?? 0 votes 0 votes Warlock lord commented Sep 25, 2017 reply Follow Share oops sorry I'm getting (n-1)(2n-1) as well..... 0 votes 0 votes Please log in or register to add a comment.
Best answer 2 votes 2 votes It is given i < 2n not i<=2n Thus the answer is $\frac{3n^{2}-3n}{2}$ If i<=2n then $\frac{3n^{2}-n}{2}$ for i<=n+1 sum is 1+2+3+...+n = $\frac{n^{2}+n}{2}$ for n+1< i < 2n sum is n(n-2) = $n^{2}-2n$ total sum = $\frac{3n^{2}-3n}{2}$ Shivam Chauhan answered Sep 25, 2017 • selected Sep 25, 2017 by just_bhavana Shivam Chauhan comment Share Follow See all 11 Comments See all 11 11 Comments reply Show 8 previous comments Warlock lord commented Sep 25, 2017 reply Follow Share So long I was considering the second loop as for(j=i...) instead of j=1 :P Curse my eyes. 0 votes 0 votes Shubhanshu commented Sep 25, 2017 reply Follow Share HAHAHA...... 0 votes 0 votes just_bhavana commented Sep 25, 2017 reply Follow Share @Shubhanshu I meant the person who answered above is correct 0 votes 0 votes Please log in or register to add a comment.