Given a year we have to find whether the year is leap year or not .
so what is leap year?
leap year are the year if it follow these two condition:
1-year is multiple of 400.
2-year is multiple of 4 but not multiple of 100.
Example:
input:2000
output:leap year
input:1600
output:leap year.
Logic:
we have to check two condition to be a year to leap year.
1-year is multiple of 400.
2-year is multiple of 4 but not multiple of 100.
# include <bits/stdc++.h> using namespace std; bool isleap(int year) { if(year%400==0) { return true; } if(year %4==0&&year%100!=0) { return true; } return false; } int main() { int year; cout<<"enter Year"<<endl; cin>>year; if(isleap(year)==true) { cout<<year<<" is a leap year"<<endl; } else { cout<<year<<" is not a leap year"<<endl; } }
Output:
enter year : 1600 1600 is a leap year
Time Complexity:O(1)
Space Complexity:O(1)