用函数计算每个月的天数,C语言问题,必须是先设计一个函数我这个哪里错了?#include #includeint main(void){ int f(int x,int y);int year ,month,day,t;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day);t==f(year,mon
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 19:47:12
用函数计算每个月的天数,C语言问题,必须是先设计一个函数我这个哪里错了?#include #includeint main(void){ int f(int x,int y);int year ,month,day,t;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day);t==f(year,mon
用函数计算每个月的天数,C语言问题,必须是先设计一个函数
我这个哪里错了?
#include
#include
int main(void)
{ int f(int x,int y);
int year ,month,day,t;
printf("输入年月日:");
scanf("%d%d%d",&year,&month,&day);
t==f(year,month);
printf("%d\n",t);
getch();
}
int f(int x,int y)
{ int z;
switch(y)
{case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
z=31;
break;
case 4:
case 6:
case 9:
case 11:
z=30;
break;
case 2:
if (x%4=0&&x%100!=0||x%400=0)
z=29;
else
z=28;
break;
}
return(z);
}
用函数计算每个月的天数,C语言问题,必须是先设计一个函数我这个哪里错了?#include #includeint main(void){ int f(int x,int y);int year ,month,day,t;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day);t==f(year,mon
scanf("%d%d%d",&year,&month,&day); //这里不好区分年月日吧,分三行写吧.
t==f(year,month); //==应该为=
if (x%4=0&&x%100!=0||x%400=0) //=应该为==
改了这3处你再试试.
#include <cstdlib>
#include <iostream>
using namespace std;
int days(int year,int month)
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
break;
case 2:
if(year%400==0 ||(year%100!=0 && year%4==0))
return 29;
else
return 28;
break;
case 4:
case 6:
case 9:
case 11:
return 30;
break;
default:
return 0;
break;
}
}
int main(int argc, char *argv[])
{
int year,month,day;
printf("输入年份:\n");
scanf("%d",&year);
printf("输入月份:\n");
scanf("%d",&month);
day=days(year,month);
printf("%d年%d月有%d天.\n",year,month,day);
system("PAUSE");
return EXIT_SUCCESS;
}