Pages

Wednesday, March 26, 2025

check leap year in C++

 #include <iostream>

using namespace std;
// code to check if a year is leap year or not
int main(){
    int num;

    cout <<"enter a year : ";
    cin >> num;
    /*
    pseudocode:
    1. take year input from user.
    2. check if the year is leap year or not.
    leap year contains 4,8,2,0 in the end.
    3. print if yes : it is a leap year.
    if no, it's not a leap year.

    */  

    if(num % 4 == 0 ) { // checks if it is divisible by 4
        cout << "it is a leap year " << endl;
    } else {
        cout << " not a leap year ";
    }

    return 0;
}

No comments:

Post a Comment

Multi-dimensional ArrayList in Java

  // import java.util.ArrayList; import java.util. * ; // import java.util.Collections; public class Classroom {     public static voi...