首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

根据年份与该年中的第几天,如何得出这天是该年的几月几号

2012-03-19 
根据年份与该年中的第几天,怎么得出这天是该年的几月几号?根据年份与该年中的第几天,怎么得出这天是该年的

根据年份与该年中的第几天,怎么得出这天是该年的几月几号?
根据年份与该年中的第几天,怎么得出这天是该年的几月几号?
例如   2007年第158天为6月7号


[解决办法]
#include <stdio.h>

int main()
{
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int year;
int days;
int leap = 0;
int i;

printf( "Enter the year and days: ");
scanf( "%d%d ", &year, &days);

if (year % 400 == 0)
leap = 1;
else if (year % 100 == 0)
leap = 0;
else if (year % 4 == 0)
leap = 1;
else
leap = 0;

month[2] += leap;
for (i=1; i <12; i++)
{
month[i] += month[i-1];
if (month[i] > days) break;
}

printf( "The day is: month: %d, day: %d\n ", i, days - month[i-1]);

}

热点排行