*分支-13. 计算天数

  1 /*
  2  * Main.c
  3  * B13-分支-13. 计算天数
  4  *  Created on: 2014年6月12日
  5  *      Author: Boomkeeper
  6  *
  7  ******测试又是木有完全通过啊*********
  8  */
  9
 10 #include <stdio.h>
 11 #include <stdlib.h>
 12
 13 #define JANUARY 31
 14 #define FEBRUARY 28
 15 #define MARCH 31
 16 #define APRIL 30
 17 #define MAY 31
 18 #define JUNE 30
 19 #define JULY 31
 20 #define AUGUST 31
 21 #define SEPTEMBER 30
 22 #define OCTOBER 31
 23 #define NOVEMBER 30
 24
 25 int day_of_year;
 26 int year,month,day;
 27
 28 void output_leap_year()
 29 {
 30     if(month==1)
 31         day_of_year=day;
 32     if(month==2)
 33         day_of_year=JANUARY+day;
 34     if(month==3)
 35         day_of_year=JANUARY+FEBRUARY+day+1;
 36     if(month==4)
 37         day_of_year=JANUARY+FEBRUARY+MARCH+day+1;
 38     if(month==5)
 39         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+day+1;
 40     if(month==6)
 41         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+day+1;
 42     if(month==7)
 43         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+day+1;
 44     if(month==8)
 45         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+day+1;
 46     if(month==9)
 47         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+day+1;
 48     if(month==10)
 49         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+day+1;
 50     if(month==11)
 51         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+OCTOBER+day+1;
 52     if(month==12)
 53         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+OCTOBER+NOVEMBER+day+1;
 54
 55     printf("%i\n",day_of_year);
 56 }
 57
 58 void output_non_leap()
 59 {
 60     if(month==1)
 61         day_of_year=day;
 62     if(month==2)
 63         day_of_year=JANUARY+day;
 64     if(month==3)
 65         day_of_year=JANUARY+FEBRUARY+day;
 66     if(month==4)
 67         day_of_year=JANUARY+FEBRUARY+MARCH+day;
 68     if(month==5)
 69         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+day;
 70     if(month==6)
 71         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+day;
 72     if(month==7)
 73         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+day;
 74     if(month==8)
 75         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+day;
 76     if(month==9)
 77         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+day;
 78     if(month==10)
 79         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+day;
 80     if(month==11)
 81         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+OCTOBER+day;
 82     if(month==12)
 83         day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+OCTOBER+NOVEMBER+day;
 84
 85     printf("%i\n",day_of_year);
 86 }
 87 int main()
 88 {
 89     char m,n;
 90
 91     scanf("%4i %c %2i  %c %2i",&year,&m,&month,&n,&day);
 92     printf("input successful\n%i %i %i\n",year,month,day);
 93
 94     if(month<=0 || day<=0)
 95         exit(0);
 96     if(month>12 || day>31)
 97         exit(0);
 98
 99     if((year%4==0) && (year%400!=0))
100     {
101         //闰年
102         output_leap_year();
103     }
104     else
105     {
106         if(year%400==0)
107         {
108             //还是闰年
109             output_leap_year();
110         }
111         else
112         {
113             //不是闰年
114             output_non_leap();
115         }
116     }
117
118     return 0;
119 }

*分支-13. 计算天数,布布扣,bubuko.com

时间: 2024-10-23 05:46:04

*分支-13. 计算天数的相关文章

分支-13. 计算天数(15)

本题要求编写程序计算某年某月某日是该年中的第几天. 输入格式: 输入在一行中按照格式"yyyy/mm/dd"(即"年/月/日")给出日期.注意:闰年的判别条件是该年年份能被4整除但不能被100整除.或者能被400整除.闰年的2月有29天. 输出格式: 在一行输出日期是该年中的第几天. 输入样例1: 2009/03/02 输出样例1: 61 输入样例2: 2000/03/02 输出样例2: 62 import java.util.Scanner; public cla

分支-11. 计算工资(15)

1 /* 2 *c语言实现 3 *B11-分支-11. 计算工资(15) 4 *Created on: 2014年6月3日 5 *Author: Boomkeeper 6 *未全部通过 7 * 8 */ 9 10 #include <stdio.h> 11 #include <stdlib.h> 12 13 float salary=0; 14 15 void newStaff(int *worktime) 16 { 17 if(*worktime<=40) 18 { 19

PHP日期操作类代码-农历-阳历转换、闰年、计算天数等

这是一个实用的PHP日期时间操作类,里面包括了公历-农历转换.转换成中文日期格式.计算农历相隔天数.根据阴历年获取生肖.获取阴历月份的天数.获取农历每年的天数.获取闰月.计算阴历日期与正月初一相隔的天数.计算2个公历(阳历)日期之间的天数.根据距离正月初一的天数计算阴历日期.获取天干地支纪年等,PHP日期操作类:Lunar.class.php代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

*分支-11. 计算工资

1 /* 2 *Main.c 3 *B11-分支-11. 计算工资(15) 4 *Created on: 2014年6月3日 5 *Author: Boomkeeper 6 * 7 ******测试未通过********* 8 */ 9 10 #include <stdio.h> 11 #include <stdlib.h> 12 13 float salary=0; 14 15 void newStaff(int *worktime) 16 { 17 //printf("

*分支-12. 计算火车运行时间

1 /* 2 * Main.c 3 * B12-分支-12. 计算火车运行时间 4 * Created on: 2014年6月4日 5 * Author: Boomkeeper 6 * 7 ********测试未通过******* 8 */ 9 #include <stdio.h> 10 #include <stdlib.h> 11 12 int startTime,arrTime; 13 int *p_startTime=&startTime; 14 int *p_arr

分支-10. 计算个人所得税

1 /* 2 * Main.c 3 * B10-分支-10. 计算个人所得税(10) 4 * Created on: 2014年5月29日 5 * Author: Boomkeeper 6 * 7 * 测试通过 8 */ 9 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 14 int main() 15 { 16 float salary=0; 17 float *ps=&salary; 18 19 scanf(&qu

计算天数

1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int j; 6 int year, month, day; 7 int sum = 0; //计算天数 8 int flag; //判断平年或者闰年 9 int a[][13] = { 10 {0,31,28,31,30,31,30,31,31,30,31,30,31}, 11 {0,31,29,31,30,31,30,31,31,30,31,30,31} 12

11周(计算天数)

/* *copyright(c) 2014,烟台大学计算机学院 *All rights reserved. *文件名称:计算天数 *作者:王忠 *完成日期:2014.10.30 *版本号:v1.0 * *问题描述:输入年月日 ,算出是该年的第几天 *输入描述:年月日 *程序输出:该年第几天 #include <iostream> using namespace std; int days(int y,int m,int d); int main() { int year,month,day;

输入日期计算天数

#include <stdio.h>void main(){ int year,month,day,daynum; printf("请输入年月日,用,号隔开,格式列(2014,5,12)\n"); scanf("%d,%d,%d",&year,&month,&day); switch(month) { case 1: daynum=day; break; case 2: daynum=30+day; break; case 3: