运行以下程序后,如果从键盘上输入china#,则输出结果为 :A、2,0 B、5,0 C、5,5 D、2,5#include main( ) { int v1=0,v2=0; char ch ; while ((ch=getchar())!='#') switch (ch ) { case 'a':case 'h':default:v1++; case '0':v2++; } printf(""%

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/16 16:07:49
运行以下程序后,如果从键盘上输入china#,则输出结果为 :A、2,0 B、5,0 C、5,5 D、2,5#include main( ) { int v1=0,v2=0; char ch ; while ((ch=getchar())!='#') switch (ch ) { case 'a':case 'h':default:v1++; case '0':v2++; } printf(

运行以下程序后,如果从键盘上输入china#,则输出结果为 :A、2,0 B、5,0 C、5,5 D、2,5#include main( ) { int v1=0,v2=0; char ch ; while ((ch=getchar())!='#') switch (ch ) { case 'a':case 'h':default:v1++; case '0':v2++; } printf(""%
运行以下程序后,如果从键盘上输入china#,则输出结果为 :A、2,0 B、5,0 C、5,5 D、2,5
#include
main( )
{ int v1=0,v2=0;
char ch ;
while ((ch=getchar())!='#')
switch (ch )
{ case 'a':
case 'h':
default:v1++;
case '0':v2++;
}
printf(""%d,%d\n"",v1,v2);" 具体求解思路

运行以下程序后,如果从键盘上输入china#,则输出结果为 :A、2,0 B、5,0 C、5,5 D、2,5#include main( ) { int v1=0,v2=0; char ch ; while ((ch=getchar())!='#') switch (ch ) { case 'a':case 'h':default:v1++; case '0':v2++; } printf(""%
当输入c时,switch语句执行情况为:
switch(ch) {case ’a’:
case ’h’: default: v1++;
case ’0’: v2++; }
因为没有break语句
v1=v1+1=1
v2=v2+1=1
当继续输入h时,switch语句的执行情况为:
switch(ch) {case ’a’:
case ’h’: default: v1++;
case ’0’: v2++;
因为没有break语句
v1=v1+1=2
v2=v2+1=2
重复上述过程,输入5个有效字符,则v1和v2执行5次自加操作,所以: v1=5, v2=5