以下程序的功能是根据输入的是y(Y)还是n(N),在屏幕上分别显示出“This is YES.”或“This is NO.”,请填空。
#include
void YesNO(char ch)
{
switch(ch)
{
case 'Y':
case 'y':printf("
This is YES.
"); ;
case 'N':
case 'n': printf("
This is NO.
");
}
}
main()
{
char ch;
printf("
Enter a char 'Y', 'y' or 'n', 'N': ");
ch= ;
printf("ch:%c",ch);
YesNo(ch);
}
#include
void YesNO(char ch)
{
switch(ch)
{
case 'Y':
case 'y':printf("
This is YES.
"); ;
case 'N':
case 'n': printf("
This is NO.
");
}
}
main()
{
char ch;
printf("
Enter a char 'Y', 'y' or 'n', 'N': ");
ch= ;
printf("ch:%c",ch);
YesNo(ch);
}
举一反三
- 以下程序的功能是根据输入的“y”(“Y”)与“n”(“N”),在屏幕上分别显示出“This is YES.”与“This is NO.”。请填空。 void YesNo(char ch) { switch(ch) { case ‘y’: case ‘Y’: printf(“\nThis is YES.\n”); _________; case ‘n’: case ‘N’: printf(“\nThis is No.\n”); } } int main() { char ch; printf(“Enter a char ‘y’,‘Y’or‘n’,‘N’:”); ch=____________; printf(“ch:%c”,ch); YesNo(ch); }
- 若有float x; int a,b; ,下面四条switch语句中正确的有( )条。 switch(x) { case x=1.0: printf(“Y”); case x=2.0: printf(“N”); } switch(a) { case a=1: printf(“Y”); case a=2: printf(“N”); } switch(b) { case b==1: printf(“Y”); case b==2: printf(“N”); } switch(x) { case 1.0: printf(“Y”); case 2.0: printf(“N”); }
- 下列程序运行时,若输入1abcedf2df<回车>,则程序的输出结果为______。 #include <stdio.h> main() char a=0,ch; while((ch=getchar())!=’\n’) if(a%2!=0&&(ch>=’a’&&ch<=’z’))ch=ch-’a’+’A’; a++;putchar(ch); printf("\n");
- 执行下列程序段,若从键盘输入字符y,则结果是【 】int x=10, y=20, z;char ch;scanf("%c", &ch);switch(ch){ case 'x':z=x+y;break; case 'y':z=x-y; default:z=0;}printf("%d",z); A: 0 B: -10 C: 30 D: 以上答案都不对
- 中国大学MOOC: 有如下程序#include <stdio.h>main() { char ch = A; while (ch < D) { printf("%d", ch - A); ch++; } printf("\n");}程序运行后的输出结果是( )