csansoon

P4.08 P95401 Function for leap years

Oct 24th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool is_leap_year(int year) {
  5.     if ((year%100)==0) {
  6.         year=(year/100);
  7.         if ((year%4)==0) return true;
  8.         else return false;
  9.     }
  10.     else if ((year%4)==0) {
  11.         return true;
  12.     }
  13.     else {
  14.         return false;
  15.     }
  16. }
  17.    
  18.    
  19. int main(){
  20.     int y;
  21.     cin >> y;
  22.     if (is_leap_year(y)) cout<<"Valid"<<endl;
  23.     else cout<<"Invalid"<<endl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment