#include #include #include int main(void) { int x = -5, y1, y2, z1, z2; x = abs(x); /* returns the absolute value of argument */ printf(" x = %d\n", x); printf(" On this computer RAND_MAX = %d\n", RAND_MAX); y1 = rand(); /* returns a random integer between 0 and RAND_MAX */ y2 = rand(); z1 = rand(); z2 = rand(); printf(" y1 = %d\n y2 = %d\n z1 = %d\n z2 = %d\n", y1, y2, z1, z2); /* Caution: each time when you run this program same random integers will be returned. To avoid repetitions you have to seed your random number generator with a current time returned by time(NULL) function */ /* seed random generator with current system time */ x = (int) time(NULL); printf("\n current system time = %d\n", x); srand( x ); printf("The random number generator has been reset\n"); /* Now, all generated random integers will be different each time you run this program */ y1 = rand(); /* returns a random integer between 0 and RAND_MAX */ y2 = rand(); z1 = rand(); z2 = rand(); printf(" y1 = %d\n y2 = %d\n z1 = %d\n z2 = %d\n", y1, y2, z1, z2); return (0); }