用C语言编程序:产生1到5间的10个随机数
2个回答
2013-09-05
展开全部
/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/#include <stdlib.h>
#include <stdio.h>
#include <time.h>void main( void )
{
int i;
int temp; /* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */
for( i = 0; i < 10;i++ )
{
temp = (rand()%5) + 1;
printf( " %d\n", temp);
}}
* with the time, then displays 10 random integers.
*/#include <stdlib.h>
#include <stdio.h>
#include <time.h>void main( void )
{
int i;
int temp; /* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */
for( i = 0; i < 10;i++ )
{
temp = (rand()%5) + 1;
printf( " %d\n", temp);
}}
2013-09-05
展开全部
#include <time.h>
#include <stdlib.h>
srand(time(0));
int main(){
int a[10],i;
for(i=0;i<10;i++){
a[i] = rand()%5+1;
}
}
#include <stdlib.h>
srand(time(0));
int main(){
int a[10],i;
for(i=0;i<10;i++){
a[i] = rand()%5+1;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询