The C Programming language Chapter 5 Control Flow 例输入两数并判断其大小关系 /*ch54.c* #include <stdio. h maino Int x,y; Enter integer x,y: 12, 23 printf("Enter integer x,y scanf("%d,%d", &x, &y); Enter integer x,y: 12, 6 if(x!=y) X>Y if(y)printf("x>Y n"); Enter integer x,y: 12,12.J else printf( X<Yn X=Y else printf("X=Y\n")
The C Programming Language Chapter 5 Control Flow 例 输入两数并判断其大小关系 /*ch5_4.c*/ #include <stdio.h> main() { int x,y; printf("Enter integer x,y:"); scanf("%d,%d",&x,&y); if(x!=y) if(x>y) printf("X>Y\n"); else printf("X<Y\n"); else printf("X==Y\n"); } Enter integer x,y:12,23 X<Y Enter integer x,y:12,6 X>Y Enter integer x,y:12,12 X==Y
The C Programming language Chapter 5 Control Flow 口 if-else association associates the else with the closest previous main( {mntx=100a=10.b=20 Ion int1=5ⅴ2=0: if(a<b) f(b!=15) if(!v1)1 else if(v2)x=10 X=-1: printf( x=%/od,, x)
The C Programming Language Chapter 5 Control Flow ❑ if-else association: ➢ associates the else with the closest previous else-less if if(……) if(……) if(……) else…... else…... else…... as: if (a= =b) if (b= =c) printf(“a= =b= =c”); else printf(“a!=b”); ➢ Uses braces { } to force the proper association main() { int x=100,a=10,b=20; int v1=5,v2=0; if (a<b) if (b!=15) if (!v1) x=1; else if(v2) x=10; x=-1; printf(“x=%d”,x); } x=-1