我是靠谱客的博主 如意柜子,这篇文章主要介绍c语言程序怎样产生随机数,用C语言编程序:产生1到5间的10个随机数,现在分享给大家,希望可以做个参考。

/* RAND.C: This program seeds the random-number generator

* with the time, then displays 10 random integers.

*/

#include

#include

#include

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( "  %dn", temp);

}

}

最后

以上就是如意柜子最近收集整理的关于c语言程序怎样产生随机数,用C语言编程序:产生1到5间的10个随机数的全部内容,更多相关c语言程序怎样产生随机数,用C语言编程序:产生1到5间内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(99)

评论列表共有 0 条评论

立即
投稿
返回
顶部