Simple Programs To Analyze
Determine the complexity of the
following programs using the number of printf
statements
executed as the efficiency measure.
Example 1
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++) printf("(%d,%d)\n",i,j);
Example 2
scanf("%d",&n);
while (n > 1) { n = n/2; printf("%d\n",n); }
Example 3
scanf("%d",&n);
for(i=1 ,m=n+66;i<=m;i++) printf("%d\n",i);
for(j=n/21,m=n/5 ;j<=m;j++) printf("%d\n",j);
Example 4
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=i;j<=n;j++) printf("(%d,%d)\n",i,j);
Example 5
void p (int n)
{
if (n < 6) printf("Done!\n");
else { printf("n = %d\n",n);
p(n/2); }
}