C语言 这个月有多少天 不考虑闰年 快快快!!3
发布网友
发布时间:2023-10-24 10:41
我来回答
共3个回答
热心网友
时间:2024-11-26 22:50
int month = 0,days = 0;
scanf("%d",&month);
switch (month) {
case 1:
days = 31;
break;
case 2:
days = 28;
break;
case 3:
days = 31;
break;
case 4:
days = 30;
break;
case 5:
days = 31;
break;
case 6:
days = 30;
break;
case 7:
days = 31;
break;
case 8:
days = 31;
break;
case 9:
days = 30;
break;
case 10:
days = 31;
break;
case 11:
days = 30;
break;
case 12:
days = 31;
break;
default:
break;
}
printf("%d月有%d天\n",month,days);
====================================
int month = 0,days = 0;
scanf("%d",&month);
if (month == 1) {
days = 31;
}else if (month == 2){
days = 28;
}else if (month == 3){
days = 31;
}else if (month == 4){
days = 30;
}else if (month == 5){
days = 31;
}else if (month == 6){
days = 30;
}else if (month == 7){
days = 31;
}else if (month == 8){
days = 31;
}else if (month == 9){
days = 30;
}else if (month == 10){
days = 31;
}else if (month == 11){
days = 30;
}else if (month == 12){
days = 31;
}
printf("%d月有%d天\n",month,days);
热心网友
时间:2024-11-26 22:51
#include<stdio.h>
int main(void)
{
int arr[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int month = 0;
scanf("%d",&month);
//if else语句
if(month >=1 && month <= 12)
{
printf("%d月有%d天。\n",month,arr[month-1]);
}
//switch语句
switch(month)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
printf("%d月有%d天。\n",month,arr[month-1]);
break;
}
return 0;
}
热心网友
时间:2024-11-26 22:51
如图,见源代码