C++随机数案例
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<iostream>
using namespace std;
#include<ctime>
int main()
{
srand((unsigned)time(NULL));
int num = rand() % 100 + 1;
int val;
while (1)
{
cout << "请输入数:" << endl;
cin >> val;
if (val > num) {
cout << "数过大" << endl;
}
else if(val<num) {
cout << "数过小" << endl;
}
else {
cout << "猜对了" << endl;
break;
}
}
return 0;
}