使用工具:
Dev-c++ 5.11
解题思路:
本题可以选择使用if-else if语句或switch语句。在使用switch语句时应该注意每当满足一个条件,执行相应的语句后,因该添加break语句,不然会导致程序继续向下执行。
下面的代码添加了循环语句,可以实现多次查询某月的英文单词,需要注意当我们定义了一个char类型的变量,要记住单引号括单个字符,双引号括多个字符。
参考代码:
#include<stdio.h>
int main()
{
int month;char r;
do
{
printf("Please enter a month number:month=");
scanf("%d",&month);
switch(month)
{
case 1:printf("This month is January!\n");break;
case 2:printf("This month is February!\n");break;
case 3:printf("This month is March!\n");break;
case 4:printf("This month is April!\n");break;
case 5:printf("This month is May!\n");break;
case 6:printf("This month is June!\n");break;
case 7:printf("This month is July!\n");break;
case 8:printf("This month is August!\n");break;
case 9:printf("This month is September!\n");break;
case 10:printf("This month is October!\n");break;
case 11:printf("This month is November!\n");break;
case 12:printf("This month is December!\n");break;
default:printf("Your number is wrong!\n");
}
printf("Do you continue!(y/n):");
scanf("%s",&r);
}
while(r=='y');
return 0;
}
运行结果: