753 views
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??

1 Answer

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}$

selected by

Related questions

3 votes
3 votes
2 answers
1
Shubhanshu asked Sep 21, 2017
536 views
Consider following program and determine the value of p after execution of program:-main() { p = 1; for(i=1;i<=n;i++) { for(j=1;j<=n;j=5*j) { p = p + n; } } }I think p's ...
0 votes
0 votes
1 answer
2
Parshu gate asked Nov 19, 2017
374 views
#include<stdio.h>int main(){ int a=2;if(a==2){ a=~a+2<<1; printf("%d",a);}}
2 votes
2 votes
1 answer
3
Nishikant kumar asked Nov 16, 2015
1,026 views
P(X:integer,Y:integer) { X = 6; A = 8; return ( X + Y ) }if the function P were invoked by the following program fragment. k = 1; L = 1; Z = (K, L);Then the value of Z wo...
0 votes
0 votes
0 answers
4
srestha asked Mar 7, 2018
603 views
#include<stdio.h int fun1(int x) { x=14; } int fun2(int x) { x=20; } int main() { int(*p)(),m,n; scanf("%d",&m); if(m) p=fun1; else p=fun2; n=(*p)(); printf("%d",n); retu...