C实现猜数字

一、概述

  案例:使用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;
}

  

原文地址:https://www.cnblogs.com/tony-yang-flutter/p/15386044.html