习题7.16.cpp

时间:2023-05-26 08:42:55
【文件属性】:

文件名称:习题7.16.cpp

文件大小:1KB

文件格式:CPP

更新时间:2023-05-26 08:42:55

谭浩强C语言课后习题

方法一: 用switch #include int main() { int i; printf("请输入月份:\n"); scanf("%d",&i); switch(i) { case 1:printf("January"); break; case 2:printf("February");break; case 3:printf("March");break; case 4:printf("April");break; case 5:printf("May");break; case 6:printf("June");break; case 7:printf("July");break; case 8:printf("August");break; case 9:printf("September");break; case 10:printf("October");break; case 11:printf("November");break; case 12:printf("December");break; } return 0; } 方法二:使用数组 #include #include int main() { char *str1[12]={ "January","February","March","April","May","June","July","August", "September","October","November","December"}; int i; printf("请输入月份:\n"); scanf("%d",&i); if(i<1||i>12) printf("输入错误,重新输入:"); else { printf("该月份是:%s",str1[i-1]); } return 0; }


网友评论