书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

闰年 平年

Description

定义一个结构体变量(包括年、月、日),编程序,要求输入年月日,计算并输出该日
在本年中第几天。注意本题一定要定义结构体变量,否则本实验成绩无效。

Input

输入三个整数(并且三个整数是合理的,既比如当输入月份的时候应该在1 至12 之间,
不应该超过这个范围)否则输出Input error!

Output

输出一个整数.既输入的日期是本月的第几天。

Sample Input

1985 1 20
2006 3 12

Sample Output

20
71
Hint

1、算法提示:如果输入的是2006 年3 月12 日,计算方法是:计算2006 年1 月1 日
到2006-3-12 是多少天。注意同样判断本年度是否闰年。
(( year%4==0 && year%100!=0 )!!(year%400==0))

 

 

我的源程序如下:

#include "stdio.h"
int Run[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int Ping[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct date
{
  int year, month, day;
}date;
int main()
{
  int i, dayth;
  while(scanf("%d%d%d", &date.year, &date.month, &date.day)==3)
  {
    if(date.month<1 || date.month>12)
    {
      printf("Input error!\n");
      continue;
    }
    dayth = 0;
    if(date.year%4==0&&date.year%100!=0 || date.year%400==0)
    {
      if(date.day>Run[date.month-1] || date.day<1)
      {
        printf("Input error!\n");
        continue;
      }
      for(i=0; i<date.month-1; i++)

dayth+=Run[i];
      dayth+=date.day;
    }
    else
    {
      if(date.day>Ping[date.month-1] || date.day<1)
      {
        printf("Input error!\n");
        continue;
      }
      for(i=0; i<date.month-1; i++)

dayth+=Ping[i];
      dayth+=date.day;
    }
    printf("%d\n", dayth);
  }
}

posted on 2011-11-03 21:08  More study needed.  阅读(342)  评论(0编辑  收藏  举报

导航

书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!