Print out leap years

Print out the leap years between 1000-2000

Idea: To
require a leap year between 1000 and 2000, you only need to know the method to solve the leap year.
Leap year conditions: If N is divisible by 4 and not divisible by 100, it is a leap year.
Or: N can be divisible by 400, which is also a leap year.
That is , if N is divisible by 400, it is also a leap year .

#include<stdio.h>
int main()
{
    
    
 int m = 2000;
 while (m > 1000)
 {
    
    
  if (m % 4 == 0 && m % 100 != 0)
  {
    
    
   printf("%d   ", m);
  }
  if (m % 100 == 0)
  {
    
    
   printf("%d   ", m);
  }
  --m;
 }
}

Here is another simple way of writing:

#include<stdio.h>
int main()
{
    
    
 int year = 0;
 for (year = 1000; year <= 2000; year++)
 {
    
    
  if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
  {
    
    
   printf("%d ", year);
  }
 }
 return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45796387/article/details/110250728