例3-1 猜数

猜数

程序核心——判断语句if-else以及其镶嵌

程序

#include<stdio.h>
int main()
{
	int mynumber=38,younumber;//计算机指定猜的数,输入的猜的数 
	
	printf("Input you number:");
	scanf("%d",&younumber);
	if(mynumber==younumber)//两数相等 
		printf("OK!your are right!");
	else
		if(younumber>mynumber)//输入数大 
			printf("sorry!you number is bigger than my number!");
		else//输入数小 
			printf("Sorry!you number is smaller than my number!");
	return 0; 
 } 

结果

Input you number:43
sorry!you number is bigger than my number!
--------------------------------
Process exited after 3.928 seconds with return value 0
请按任意键继续. . .

分析

重点:判断语句之间的镶嵌,注意判断条件是否存在遗漏

posted on 2019-03-15 15:03  凯*凯  阅读(109)  评论(0编辑  收藏  举报

导航