retagged by
614 views

2 Answers

Best answer
3 votes
3 votes

 From i=1 to n

 "if(j<i)" this condition true till only for every j=i-1 times
 So, P=0+1+2....+(n-1)=n(n-1)/2


and for i=(n+1) to (2n-1)

"if(j<i)" This will true n-1 times 
P= n(n-1)

Total value of P=n(n-1)+(n(n-1))/2=3(n2-n)/2
 

  

selected by
0 votes
0 votes
Let's calculate number of pairs (j,i) such that j<i.

(1,2),(1,3),...,(1,2n) = Total 2n-1 pairs.

(2,3),(2,4),...,(2,2n) = Total 2n-2 pairs.

.

.

.

(n,n+1)(n,n+2),...,(n,2n) = Total 2n-n = n pairs.

Therefore Total pairs overall = n(n+2n-1)/2.
edited by
Answer:

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
4
24aaaa23 asked Oct 1, 2023
268 views
int foo(int n){if(n<3)return 1;else return (foo(n-1) + foo(n-3) + 1);}Let ‘m’ denote the number of invocations of function foo and ‘n’ denote the return val...