qfedu-basic-level/day8/d5.cpp

21 lines
402 B
C++
Raw Permalink Normal View History

2023-06-23 17:31:07 +08:00
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int arr[5];
int i = 0;
// 生成 5 个随机数并输出
while (i < 5)
{
arr[i] = rand() % 100; // 生成 0~99 之间的随机数: max = 99, min = 0 -> rand() % (max - min + 1) + min
cout << "arr[" << i << "] = " << arr[i] << endl;
i++;
}
return 0;
}