Monday, February 20, 2017

Random between 0 to 100.

#include <stdio.h>
#include <stdlib.h>
int main()
{
   int i;
   time_t my_sys_time;
   //To set random number generator as per system time 
   srand((unsigned) time(&my_sys_time));

   //To print 10 random numbers from 0 to 100
   for( i = 0 ; i < 10 ; i++ ) 
   {
      printf("%d ", rand()%100);
   }
   return(0);
}
Output of program
16 45 14 21 60 18 65 3 41 34

No comments:

Post a Comment