1. Random number generation
The random number produced by int rand (void) is the same as the last time it was run, and to be different, initialize it with the function srand ().
void Srand (unsigned int seed) initializes the random number generator.
To run a code snippet:
Srand ((unsigned) time (NULL));
Rand ();
To generate random numbers.
2. Calculate Program Run time
time_t Start=clock ();
time_t End=clock ();
printf ("The Running time is:%f\n", double (End-begin)/clocks_per_sec); How many seconds are consumed by the program execution.
The clock () calculates the CPU execution time, and if there are multiple cores in parallel, the final result is the sum of the compute time on each CPU. The constant clocks_per_sec indicates how many clock units will be in a second.
3. Program hibernation
If you want the program to hibernate for 3 seconds, Windows uses sleep (3) and Linux uses sleep.
4. Strlen is used to measure how many characters are in a character array, without '/0 ', and sizeof is used to measure how much space the array occupies, so when the character array length is computed, its value is strlen (arr) +1. (a char type occupies one byte).
C Language Programming Small tip