现在的位置: 首页 > 综合 > 正文

c语言输入年月日,判断是这一年的第几天

2014年08月29日 ⁄ 综合 ⁄ 共 595字 ⁄ 字号 评论关闭

// numOfYear.cpp : Defines the entry point for the console application.
//输入具体日期,判断出这一年的第多少天。

#include "stdafx.h"
#include "stdio.h"

int main(int argc, char* argv[])
{
int year,month,day;
int i,j;
int num=0;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};//平年2月28天 365天
int b[12]={31,29,31,30,31,30,31,31,30,31,30,31};//闰年2月29天 366天
bool x;//判断是否为闰年
printf("请输入年月日\n");
scanf("%d%d%d",&year,&month,&day);
if ((year%4==0)&&(year%100!=0)||(year%4==0)&&(year%400==0))
x=true;//是闰年
else
x=false;//是平年
if (x)
{
for (i=0;i<month-1;i++)
num+=b[i];
num=num+day;
}
else
{
for (j=0;j<month-1;j++)
num+=a[j];
num+=day;
}
printf("今天是%d年的第%d天\n",year,num);
return 0;
}

抱歉!评论已关闭.