To calculate the time in c programming we can use clock() function in c which is define in time.h header file clock can call at the beginning and end of the code for which will help to measure time.
In this process subtract the obtain values for the clock function, and then divide by CLOCKS_PER_SEC (the number of clock ticks per second)to get time.
Read also :- ellipse function in C programming
Syntax for clock function in c
#include <time.h> clock_t start, end; double cpu_time_used; start = clock(); ... /* Do the work. */ end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
Following C program will tell how to measure time with the help of clock() function in c and we also use fun() function which will help to terminate the process after enter key press to terminate.
Example program for clock() function in c
OUTPUT :-
clock function in c |
0 comments:
Post a Comment