一、概述

  案例:使用C语言实现猜数字的功能。控制台会提是“大了”,“小了”,“猜对了”

  目的:记录C的学习过程,并无其他实际含义

二、示例代码

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


using namespace std;

int main(int argc, char const *argv[])
{
	/* code */
	srand(time(NULL));//随机数种子
	int n = 0;
	int num = rand()%100;//生成随机数字
	cout << "rand num is "<< num<<endl;
	for(;;){
		cout<< "please input num:"<<endl;
		scanf("%d",&n);
		if(n<num){
			cout << "Is too litter"<<endl;
		}else if(n>num){
			cout << "Is too biger"<<endl;
		}else{
			cout << "Is very good"<<endl;
			break;
		}


	}
	cout << "I am is "<< num<<endl;
	return 0;
}

  

相关文章:

  • 2022-12-23
  • 2021-05-18
  • 2022-02-08
  • 2022-12-23
  • 2021-04-06
  • 2022-01-13
  • 2021-09-07
  • 2021-12-05
猜你喜欢
  • 2022-01-13
  • 2021-12-16
  • 2021-11-30
  • 2021-11-30
  • 2022-12-23
  • 2021-09-20
  • 2021-12-08
相关资源
相似解决方案