5.5 Is this year a leap year? (C++) kkmd66

Error prone:

1. The stream operation will time out! Only scanf and printf can be used.

Description:

Input a certain year, please write a program to determine whether the year is a leap year.

Input:

The input contains multiple sets of data, and each set of data includes a positive integer Y.

Output:

For each set of test data, if the year is a leap year, output "Leap Year", otherwise output "Not Leap Year".

Sample Input:

1989
2000

Sample Output:

Not Leap Year
Leap Year

#include<iostream>

using namespace std;

int main() {
    
    
    int year;
    while (scanf("%d", &year) != EOF) {
    
    
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
    
    
            printf("Leap Year\n");
        } else {
    
    
            printf("Not Leap Year\n");
        }
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324199590&siteId=291194637