C语言 编写程序,当输入数月份时,显示相应英文月份名称。

2024-12-01 04:32:35
推荐回答(2个)
回答1:

#include

int main(void){

    char *month[]={"January","February","March","April","May","June","July","August","September","October","November","December"};

    int i;

    printf("**************输入0结束循环************\n");

    while(1){

        printf("请输入月份号:");

        scanf("%d",&i);

        if(i==0){

        return 0;                                                           

        }   

        printf("该月的英文名为:%s\n",month[i-1]);

    }   

}

回答2:

#include
void main()
{
int n;
printf("请输入数字:");
scanf("%d",&n);
switch(n)
{
case 1:printf("Jan \n");break;
case 2:printf("Feb \n");break;
case 3:printf("Mar \n");break;
case 4:printf("Apr \n");break;
case 5:printf("May \n");break;
case 6:printf("Jun \n");break;
case 7:printf("Jul \n");break;
case 8:printf("Agu \n");break;
case 9:printf("Sep \n");break;
case 10:printf("Oct \n");break;
case 11:printf("Nov \n");break;
case 12:printf("Dec \n");break;
}
}