Friday, February 23, 2018

C++ program to get a list of leap year from 1996 to 2000.( Or years in a range)

Source Code:- 
----------------------------------------------------------- 
#include<iostream>
using namespace std;
int main()
{
    int a,n,i,k=0;
    cout<<"\"This program will show Leap Years between a range. \""<<endl<<endl;
    cout<<"What is the starting year ?. Give a starting year. "<<endl;     cin>>a;
    cout<<"What is the ending year ?. Give a ending year. "<<endl;     cin>>n;
    cout<<endl;
    cout<<"Leap Years between "<<a<< " to "<<n<<" are :"<<endl;

    for(i=a;i<=n;i++)
        if(((i%400==0) || (i%100 !=0)) && ( i%4==0)) 
        {
            cout<<i<<" ";
            k++;
        }

    if(k==0) 
    {
        cout<<0<<endl;
        cout<<"It means there is no leapyears between "<<a<<" to "<<n;
    }
}
------------------------------------------------------------ 
Output: 

 

No comments:

Post a Comment

Hardware/System Requirements for the Ubuntu 18.04 LTS.

According to the official Website of  Ubuntu minimum system requirements to install Ubuntu 18.04 LTS  are:-  2 GHz dual core processor or...