C or C++ Program to Show Leap Years between a Range

This article show the program to find all the leap years between a range in c/c++.

C Code for Leap Years between a Range

#include
#include
int main()
{
    clrscr();
    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;
    }
    getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *