In: Computer Science
All years that are evenly divisible by 400 or are evenly divisible by four and not evenly divisible 100 are leap years. For example, since 1600 is evenly divisible by 400, the year 1600 was a leap year. Similarly, since 1988 is evenly divisible by four but not 100, the year 1988 was also a leap year. Using this information, write a C++ program that accepts the year as user input, determines if the year is a leap year, and displays an appropriate message that tells the user whether the entered year is or is not a leap year.
C++ Program
#include <iostream>
using namespace std;
bool LeapYear(int year){//function LeapYear
if(year%400==0)
return true;
if(year%4==0 && year%100!=0)
return true;
return false;
}
int main()//main
{
int year;
cout<<"Enter Year: ";
cin>>year;
bool flag=LeapYear(year);//call function LeapYear
if(flag==true)
cout<<year<<" is a Leap Year";
else
cout<<year<<" is not a Leap Year";
return 0;
}
OUTPUT