![](https://csdnimg.cn/release/download_crawler_static/87610410/bg8.jpg)
第 5 次循环
执行 if 语句。10 等于 10,if 语句的条件表达式成立,执行 break,跳出循环。
从 break 跳出至 for 语句的下一条语句。执行 printf(“%d %d”,y,x);
输出当前的 y 与 x.结果为 10 5
14.
#include<stdio.h>
main( )
{ char ch;
ch=getchar( );
switch(ch)
{ case ‘A’ : printf(“%c”,’A’);
case ‘B’ : printf(“%c”,’B’); break;
default: printf(“%s\n”,”other”);
} }
当从键盘输入字母 A 时,运行结果为:AB
switch(表达式)
{ case 常量 1 :语句 1
case 常量 2 :语句 2
┇ ┇ ┇
case 常量 n :语句 n
default : 语句 n+1
}
其中表达式,常量 1,…,常量 n 都为整型或字符型
case 相当于给出执行程序的入口和起始位置,若找到匹配的常量,则从此处开始往下执行程
序,不再匹配常量,直至遇到 break 或 switch 结束
本题过程:
首先从键盘接收一个字符’A’并将其放在变量 ch 中。
执行 switch 语句。Switch 后面的条件表达式为 ch,因此表达式的值即为字符’A’. 用字
符’A’依次与下面的 case 中的常量匹配。
与第 1 个 case 后的常量匹配,则从其后的语句开始往下执行程序(在执行过程中不再
进行匹配。)因此先执行 printf(“%c”,’A’),屏幕上输出 A;再往下继续执行 printf(“%c”,’B’),
屏幕上输出 B;再继续执行 break, 此时跳出 switch 语句。
15.
#include <stdio.h>
main( )
{ int a=1,b=0;
scanf(“%d”,&a);