請計算下列C語言程式片斷或函數的頻率計數:
(1) for ( i = 0; i < n; i++ )
for ( j = 0; j < n; j++ )
for ( k = 0; k < n; k++)
a = a + 1;
頻率計數 :
=n+1
=n*(n+1) = n2+n
=n*n*(n+1)= n3+n2
=n3
=2n3+2n2+2n+1
(2) i = 1;
while ( i <= n ) {
a = a + 1;
i++;
}
頻率計數 :
=1
=n+1
=n
=n
=3n+2
評分: ★★★★☆▲
回覆刪除Excellent !