C difftime() function
C difftime() function - Compute the difference between two calendar time values
The difftime() function is used to compute the difference in seconds between two times.
Syntax:
double difftime(time_t time1, time_t time2)
Parameters:
Name | Description | Required /Optional |
---|---|---|
time1 | Ending time. | Required |
time2 | Beginning time. | Required |
Return value from difftime()
- The ctime() function returns a pointer to the character string result.
- If the function is unsuccessful, it returns NULL.
Example: difftime() function
The following example shows the usage of difftime() function.
Output:
n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 n = 10 Program takes an average of 0.909091 seconds to find 5 even numbers and 5 odd numbers.
C Programming Code Editor:
Previous C Programming: C ctime()
Next C Programming: C gmtime()