你把这个程序的birth都改成start就行了
其实不改也无妨
#include <stdio.h>
//判断是否闰年
bool IsLeapYear( int year )
{
return ( year % 400==0 || ( year %4==0 && year %100 !=0 ) );
}
//获取某年中某月的天数
int GetDaysOfMonth( int year, int month )
{
int day = 31;
if ( month >12 || month < 0 )
{
return 0;
}
switch ( month )
{
case 4:
case 6:
case 9:
case 11:
day=30;
break;
case 2:
day = ( IsLeapYear( year) ) ? 29 : 28;
break;
default:
break;
}
return day;
}
//计算两个日期间的天数
void FunctionFour( int birthYear, int birthMonth, int birthDay, int year, int month, int day )
{
int iResult=0;
for ( int i=birthYear; i<=year; i++ )
{
iResult += ( ( IsLeapYear(i) ) ? 366 : 365);
}
for ( int i=1; i<birthMonth; i++ )
{
iResult -= GetDaysOfMonth( birthYear, i );
}
for ( int i=1; i < birthDay; i++ )
{
iResult--;
}
for ( int i=month; i <=12; i++ )
{
iResult -= GetDaysOfMonth( year, i );
}
for ( int i=1; i < day; i++ )
{
iResult++;
}
printf("\n%d年%d月%日-%d年%d月%d日 = %d天\n", year, month, day, birthYear, birthMonth, birthDay );
}
int main()
{
char ch;
int year, month, day;
int birthYear, birthMonth, birthDay;
printf( "请输入你的生日(年月日, 以空格分隔):");
scanf( "%d%d%d", &birthYear, &birthMonth, &day );
printf( "\n请输入计算日期(年月日, 以空格分隔):");
scanf( "%d%d%d", &year, &month, &birthDay );
FunctionFour( birthYear, birthMonth, birthDay, year, month, day);
printf( "Any key to exit...");
scanf( "%c", &ch);
return 0;
}
参考资料:http://zhidao.baidu.com/question/41148459.html?si=8