C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

Consider the following I/O samples.




SAMPLE INPUT : 200 300

SAMPLE OUTPUT:  204 208 212 216 220 224 228 232 236 240 244 248 

                                  252 256 260 264 268 272 276 280 284 288 292 296



C PROGRAM:

#include <stdio.h>
int checkLeapYear(int year)
{
    if( (year % 400==0)||(year%4==0 && year%100!=0) )
        return 1;
    else
        return 0;
}
 
int main()
{
    int i,n,s;
    scanf("%d %d",&s,&n);
    printf("Leap years from %d to %d:\n\n",s,n);
    for(i=s;i<=n;i++)
    {
        if(checkLeapYear(i))
            printf("%d ",i);
    }
    return 0;

}

 

OUTPUT:

 



  

The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 
If you have any feedback about this article and want to improve this, please comment in the comment section.

 

Comments

Popular posts from this blog

HOLLOW INVERTED PYRAMID STAR

HOLLOW PYRAMID STAR PATTERN

INNER REDUCING PATTERN