C++ program to check whether the given year is leap year or not using if-else and class.
C++ program to check whether the given year is leap year or not using if-else
#include<iostream>
using namespace std;
int main()
{
int year;
cout<<"Enter any year: ";
cin>>year;
if(((year%4==0)&&(year%100!=0))||(year%400==0))
cout<<year<<" is a leap year";
else
cout<<year<<"is not a leap year";
}
using namespace std;
int main()
{
int year;
cout<<"Enter any year: ";
cin>>year;
if(((year%4==0)&&(year%100!=0))||(year%400==0))
cout<<year<<" is a leap year";
else
cout<<year<<"is not a leap year";
}
C++ program to check whether the given year is leap year or not using class
#include<iostream>
using namespace std;
class check
{
private:
int year;
public:
void getyear()
{
cout<<"Enter any year: ";
cin>>year;
}
void checkyear()
{
if(((year%4==0)&&(year%100!=0))||(year%400==0))
cout<<year<<" is a leap year";
else
cout<<year<<"is not a leap year";
}
};
int main()
{
check leap;
leap.getyear();
leap.checkyear();
return 0;
}
using namespace std;
class check
{
private:
int year;
public:
void getyear()
{
cout<<"Enter any year: ";
cin>>year;
}
void checkyear()
{
if(((year%4==0)&&(year%100!=0))||(year%400==0))
cout<<year<<" is a leap year";
else
cout<<year<<"is not a leap year";
}
};
int main()
{
check leap;
leap.getyear();
leap.checkyear();
return 0;
}
No comments:
Post a Comment