用C语言产生1到n的随机数 要求:输入人数可以得到随机数# include # include # include int main(void){\x05srand((unsigned int) time(0));\x05int n;\x05scanf("%d",&n);\x05int a[n];\x05for (int i = 0; i < n; ++i)\x05{\x05\x05a[i] = ra

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 06:33:47
用C语言产生1到n的随机数要求:输入人数可以得到随机数#include#include#includeintmain(void){\x05srand((unsignedint)time(0));\x0

用C语言产生1到n的随机数 要求:输入人数可以得到随机数# include # include # include int main(void){\x05srand((unsigned int) time(0));\x05int n;\x05scanf("%d",&n);\x05int a[n];\x05for (int i = 0; i < n; ++i)\x05{\x05\x05a[i] = ra
用C语言产生1到n的随机数 要求:输入人数可以得到随机数
# include
# include
# include
int main(void)
{
\x05srand((unsigned int) time(0));
\x05int n;
\x05scanf("%d",&n);
\x05int a[n];
\x05for (int i = 0; i < n; ++i)
\x05{
\x05\x05a[i] = rand() % 67 + 1;
\x05\x05printf("%d\n",a[i]);
\x05}
\x05return 0;
}或者看这个程序,为什么输入人数会报错

用C语言产生1到n的随机数 要求:输入人数可以得到随机数# include # include # include int main(void){\x05srand((unsigned int) time(0));\x05int n;\x05scanf("%d",&n);\x05int a[n];\x05for (int i = 0; i < n; ++i)\x05{\x05\x05a[i] = ra
# include
# include
# include
int main(void)
{
srand((unsigned int) time(0));
int n,*a; //改过!改过!改过!改过!改过!
scanf("%d", &n);
a=new int[n]; //改过!改过!改过!改过!改过!
for (int i = 0; i < n; ++i)
{
a[i] = rand() % 67 + 1;
printf("%d\n", a[i]);
}
delete []a; //改过!改过!改过!改过!改过!
return 0;
}