随机数是怎么算的
2025-10-12 17:58:52
发布于:广东
代码是:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
int n ;
srand(time(0)); //产生随机数种子
int a = rand()%10;
//cout<<"悄悄告诉你,答案是:"<<a<<endl;
cin >> n;
if(n == a){
cout << "猜对了" << endl ;
}else{
cout << "猜错了" << endl ;
}
cout << "中奖的号码是" << a;
return 0;
}
这里空空如也











有帮助,赞一个