zoukankan      html  css  js  c++  java
  • 判断1000年---2000年之间的闰年

    在写程序之前应该要知道闰年的定义:

    普通闰年:能被4整除但不能被100整除的年份为普通闰年。(如2004年就是闰年,1999年不是闰年);
    世纪闰年:能被400整除的为世纪闰年。(如2000年是闰年,1900年不是闰年);
     
    思路:
    先用for循环语句来排列年份,在用if语句将普通闰年和世纪润年分开来判断。
    世纪:year%400==0 可以直接求得。
    普通:year%4==0 && year%100!=0 则证明年份可以被4整除,并且不会被100整除。
     1 # include<stdio.h>
     2 int main()
     3 {
     4     int count = 0;//表示个数
     5     int year;//表示年份
     6     for (year = 1000;year <= 2000;year++)
     7     {
     8         if (year% 400 == 0)//判断是否为世纪润年
     9         {
    10             printf("%d ", year);
    11             count++;
    12         }
    13         else if(year % 4 == 0 && year % 100 != 0)//判断是否为普通润年
    14         {
    15             printf("%d ", year);
    16             count++;
    17         }
    18     }
    19     printf("count=%d
    ",count);
    20 
    21     return 0;
    22 }
  • 相关阅读:
    D. Constructing the Array
    B. Navigation System
    B. Dreamoon Likes Sequences
    A. Linova and Kingdom
    G. Special Permutation
    B. Xenia and Colorful Gems
    Firetrucks Are Red
    java getInstance()的使用
    java 静态代理和动态代理
    java 类加载机制和反射机制
  • 原文地址:https://www.cnblogs.com/cuckoo-/p/10257456.html
Copyright © 2011-2022 走看看