取随机数

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
	int index=1;
	srand(time(0));
	int num=rand()%100;
	int a;
	do{
		cout<<"这是第"<<index<<"次"<<endl;
		cin>>a;
		if(a==num){
			cout<<"相等"<<endl;
			break;
		}else if(a>num){
			cout<<"大了"<<endl;
		}else{
			cout<<"小了"<<endl;
		}
		index++;
	}while(true);
	cout<<"用了"<<index<<"次";
	return 0;
}

  

posted @ 2023-03-25 16:37  陈若麟  阅读(15)  评论(0编辑  收藏  举报