C语言如何生成10——99内的随机数
C语言怎么生成10——99内的随机数
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int n;
strand((int)time(0));
printf("请输入产生随机数的个数:");
scanf("%d",&n);
printf("%d",rand());
后面要怎么办呢
------解决方案--------------------
------解决方案--------------------
rand()%90+10
------解决方案--------------------
这样更合适。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int n;
strand((int)time(0));
printf("请输入产生随机数的个数:");
scanf("%d",&n);
printf("%d",rand());
后面要怎么办呢
------解决方案--------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
int a;
srand(time(NULL));
printf("请输入产生随机数的范围:");
scanf("%d",&n); //n=99
a=(rand()%(n-10)+10;
printf("The Random Number is %d .\n", a);
}
------解决方案--------------------
rand()%90+10
------解决方案--------------------
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
int i,n;
i=0;
time_t t1; /* 用于存放时间 */
time(&t1); /* 取得当前系统时间 */
srand(t1); /* 设置随机数的种子,使得每次运行试产生不同的随机数 */
printf("请输入产生随机数的个数:\n");
scanf("%d",&n);
while(i<n)
{
printf("第%d个随机数:%d\n",i+1,rand()%90+10);
i++;
}
return 0;
}
这样更合适。