如何用C语言编写输入出生年月,求
//帮你搞了一个,刚有点小错误,修正了一下
#include"stdio。h"
#include"math。h"
typedef struct
{
int year;
int month;
int day;
}Date;
int date[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
int judge(int year) //判断是否为闰年//
{
int flag=0;
if((yea...全部
//帮你搞了一个,刚有点小错误,修正了一下
#include"stdio。h"
#include"math。h"
typedef struct
{
int year;
int month;
int day;
}Date;
int date[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
int judge(int year) //判断是否为闰年//
{
int flag=0;
if((year%4==0&&year%100!=0)||year%400==0) flag=1;
else flag=0;
return flag;
}
Date work(Date user[2]) //计算两个日期相差//
{
Date rec,tmpdate;
if(user[1]。
month>user[0]。month||(user[1]。month==user[0]。month&&user[1]。day>=user[0]。day))
rec。year=user[1]。
year-user[0]。year;
else
rec。year=user[1]。year-user[0]。year-1;
tmpdate。year=user[0]。year+rec。
year;
tmpdate。month=user[0]。month;
tmpdate。day=user[0]。day;
int m=judge(user[1]。year);
if(tmpdate。
year month;
rec。day= user[1]。day-tmpdate。day;
}
else
{
rec。month= 11-tmpdate。month+user[1]。
month;
rec。day=date[m][user[1]。month]-tmpdate。day+ user[1]。day;
}
}
else
{
if(tmpdate。
day<= user[1]。day)
{
rec。month= user[1]。month-user[0]。month;
rec。day= user[1]。day-tmpdate。
day;
}
else
{
rec。month= user[1]。month-1;
rec。day=date[m][user[1]。month]-tmpdate。day+ user[1]。
day;
}
}
return rec;
}
int main()
{
Date user[2];
int i;
printf("Please input 2 dates(such as 2008。
10。2)。\n");
for(i=0;i<2;i++)
{
scanf("%d。%d。%d",&user[i]。year,&user[i]。month,&user[i]。day);
}
Date d=work(user);
printf("There are %d years %d month %d days。
\n",d。year,d。month,d。day);
getchar()();
}。收起