您好,我想打印从 30 到 -30 的数字,这是我的代码
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
srand(time(0));
int arr[20] = {0};
for(int i = 0; i < 20; i++){
arr[i] = rand() % 30+(-30);
}
for(int i = 0; i < 20; i++){
cout << arr[i] << " "<<endl;
}
return 0;
}
我不知道为什么,但所有数字都是负数?