Exercise 3-5 Output leap year (15 points)

All output in the 21st century leap year since a year cutoff year. Note: Criterion leap year is the year of the year divisible by 4 but not divisible by 100, or divisible by 400.

Input formats:

Enter a given year ended 21st century in a row.

Output formats:

All leap years progressive output to meet the conditions that each year per line. Enter the 21st century, if not the year of the output "Invalid year!". If there is any leap year, the output "None".

Sample Input 1:

2048
 

Output Sample 1:

2004
2008
2012
2016
2020
2024
2028
2032
2036
2040
2044
2048
 

Sample Input 2:

2000
 

Output Sample 2:

Invalid year!

#include<stdio.h>
int main(void){
    int n,i,count=0;
    
    scanf("%d",&n);
    if(n>2100||n<=2000)
        printf("Invalid year!");
    else if(n>2000&&n<=2100){
        for(i=2001;i<=n;i++){
            if((i%4==0&&i%100!=0)||(i%400==0)){ 
                count=1;
                printf("%d\n",i);        
            }
        } 
        if(count==0)
            printf("None");
        
        return 0;    
    }
    
        
}

 

Guess you like

Origin www.cnblogs.com/Kimsohyun/p/12578885.html