hi,
the soln is as follows...
Value of i changes from 0 to n-2
Value of j changes as follows..1 to n-1
2 to n-1
.....
n-2 to n-1
Value of k changes as followsFor j=1 to n-12 to n
3 to n
4 to n
.....
n to n
for j=2 to n-13 to n
4 to n
....
n to n
......
for j= n-2 to n-1n-1 to n
n to n
Thus total number of executions is summation of number of times value of k changes which is
=(n-2)(n to n)+(n-2)(n-1 to n)+(n-3)(n-2 to n)....1(2 to n)
=(n-2)(n to n)+(n-2)(n-1 to n)+(n-3)(n-2 to n)....1(2 to n)+0(1 to n)
=(n-2)(1) + [(n-2)2+(n-3)3+......+(1)(n-1)+(0)(n)]
=(n-2)(1) + [ summation of (n-i)i ] where i =2 to n
=(n-2)(1) + [ summation of (n-i)i ] - n +1 where i= 1 to n
the rest can be solved easily using the formulas
1+2+3....n= n(n+1)/2
1^2+2^2....n^2=(n)(n+1)(2n+1)/6