Click here to Skip to main content
15,895,792 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There is sevelal loop sentences.
Please give out the times of the sentences labelled with '@':
(1) i=1; k=0;
   while ( i<=n-1) {
    @ k += 10 * i;
      i++;
   }
 (2) i=1; k=0;
   do {
    @ k +=10 * i;
      i++;
   } while(i<=n-1); 
 (3) i = 1; k = 0;
   while (i<=n-1) { 
      i++ ;
     @ k+= 10 * i;
   }
 (4) k=0;
   for( i=1; i<=n; i++) {
    for (j=i ; j<=n; j++)
     @ k++;
   }
 (5) for( i=1; i<=n; i++) { 
    for (j=1; j<=i; j++) {
     for (k=1; k<=j; k++)
      @ x += delta;
    }
   }
 (6) i=1; j=0;
   while (i+j<=n) {
    @ if (i>j ) j++ ;
      else i++ ;
   }
 (7) x=n; y=0; // n 是不小于1的常数
   while (x>=(y+1)*(y+1)) {
   @ y++;
   }
 (8) x=91; y=100;
   while (y>0 ) {
   @ if (x>100 ) { x -= 10; y- -; } 
     else x++;
   }
Posted
Updated 21-Apr-10 2:14am
v4

Ok, and what is your problem about?
:)

JanTCode wrote:
I want to know the executing times of the sentence labled by '@' when n is gived

I think you've at least two options:
  • Count.
  • Develop a program for counting on your behalf.
 
Share this answer
 
v3
I want to know the executing times of the sentence labled by '@' when n is gived
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900