第一种:10内的随机数(固定顺序):
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int arr[10];
for (size_t i = 0; i < 10; i++)
{
arr[i] = rand() % 10;
printf("%dn", arr[i]);
}
system("pause");
return 0;
}

第二种:10内的随机数(可能重复):
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int arr[10];
srand((unsigned)time(NULL));
for (size_t i = 0; i < 10; i++)
{
arr[i] = rand() % 10;
printf("%dn", arr[i]);
}
system("pause");
return 0;
}

最后
以上就是怡然砖头最近收集整理的关于C/c++ 10内的随机数的全部内容,更多相关C/c++内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复