-5
int i=0;
while(i<=100)
{
    printf("hello world....\n");
    i++;
}

For the above program, how can I find the total time of execution of while loop.

5
  • 5
    The body of the loop is not executed. Commented Jun 16, 2017 at 5:42
  • 1
    For loop execution while( i <= 100 ). It's already been answered here: stackoverflow.com/questions/5248915/execution-time-of-c-program Commented Jun 16, 2017 at 5:42
  • 1
    Could have searched before asking the question. This has already been answered. Commented Jun 16, 2017 at 5:43
  • 2
    That will be executed really, really fast :-) You probably want to change while(i>=100) into while(i <= 100) Commented Jun 16, 2017 at 5:53
  • thank you frnds. i have searched before but i did'nt find may be I am lack of searching knowledge . anyway thanks. Commented Jun 16, 2017 at 5:57

1 Answer 1

1

In header file time.h have that function. you can use that. You can see there is a clock_t variable called start which calls a clock() function. try this:

clock_t start = clock();
for ( i = 0; i < 100; i++ )
            rand();
    printf ( "%f\n", ( (double)clock() - start ) / CLOCKS_PER_SEC );

it will give you execution time. for this check your conditioj in while loop. it should "< 100" i think. check this code it will work for you.

Sign up to request clarification or add additional context in comments.

4 Comments

loop will not execute i=0 and in while loop it says i>=100
i mentioned it in edit check this. its a running code.
great yeap now it works
now its working thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.