|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
/*************************************************
**输入一个某年某月某日,输出为这一天为这一天的第几天**
*************************************************/
#include <stdio.h>
int main()
{
int a ,b1 , b2 ,c ,leap ,sum;
printf("please input year/month/day: \n"); //输入年月份
scanf("%d%d%d",&a,&b1,&c);
if (a%4==0) //判断是否为闰年
{
if (a%100==0)
{
if(a%400==0)
leap=1;
else
leap=0;
}
else
leap=1;
}
else
leap=0;
if(leap) //leap为判断闰年的标志
{
printf("%dis a leap year\n",a);
switch(b1) //闰年每个月天数的差别
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: b2 = 31 ;break;
case 2: b2 = 29 ;break;
case 4:
case 6:
case 9:
case 11: b2 = 30 ;break;
}
}
else //非闰年每个月份天数的差别
{
printf("%dis not a leap year\n",a);
switch(b1)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: b2 = 31 ;break;
case 2: b2 = 28 ;break;
case 4:
case 6:
case 9:
case 11: b2 = 30 ;break;
}
}
if (b1==1) //计算天数
sum = b2 + a;
else if (b1==2)
sum = b2 + a + 31;
else if (b1==3)
sum = b2 * 2 + a;
else if (b1==4)
sum = b2 + 31 * 2 + 30 + a;
else if (b1==5)
sum = b2
printf("%d年%d月%d日为%d年的第%d天\n",a ,b1 ,c ,a ,sum);
}
计算天数怎么计算
#pragma warning(disable : 4996)
#include <stdio.h>
#include <windows.h>
#include <stdbool.h>
int main(void) {
int year, month, day, sum = 0;
bool n = false;
int Year[] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
printf("please input year/month/day: ");
scanf("%d %d %d", &year,&month, &day);
if ((year % 4 == 0) && (year % 100 != 0)) {
n = true;
}
if (n) {
Year[1] = 28;
}
for (int i = 0; i < month; i++) {
sum += Year[i];
}
sum = sum - Year[month] + day;
printf("%d年 %d月 %d日 是%d年的第%d天\n", year,month,day,year,sum);
system("pause");
return 0;
}
|
|