int main(void)
{
int i;
time_t t;
float x;
int y;
srand((unsigned) time(&t));
printf("Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
{
x=rand(); /* gives a floating number */
y=(int)x%100; /* cast into a integer of range 0 ~ 99 */
printf("rand() modulus l00 is %d \n",y );
}
getchar();
return 0;
}
{
int i;
time_t t;
float x;
int y;
srand((unsigned) time(&t));
printf("Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
{
x=rand(); /* gives a floating number */
y=(int)x%100; /* cast into a integer of range 0 ~ 99 */
printf("rand() modulus l00 is %d \n",y );
}
getchar();
return 0;
}
留言
張貼留言