楼主你好!
#include
#include
#include
int main()
{
int i;
srand((unsigned int)time(NULL));
i=1+rand()%100;
printf("%d ", i);
return 0;
}
这是一个产生1到100之间的一个随机数的用法例子!
希望我的回答对你有帮助!
#include
#include
#include
#include
void main( void )
{
int i;
/* 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++ )
printf( " %6d\n", rand() );
}
前面最好在加一条语句:srand(time(0));建议:写一个产生随机数的函数吧,以后用起来方便
number=1+rand()%10number是你要的随机数上面是从1到10产生随机数