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

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

闰年 平年

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   More study needed.  阅读(348)  评论(0编辑  收藏  举报

编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
< 2011年11月 >
30 31 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 28 29 30 1 2 3
4 5 6 7 8 9 10

导航

统计

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

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

点击右上角即可分享
微信分享提示