My Project - Video Waker Alarm
Get Video alarm on Google Play

c program for leap year


c program for leap year. A year will be a leap year if it is divisible by 400 but not by 100, if not divisible by both and divisible by 4 then leap year otherwise not a leap year. Here is the algorithm:

if year is divisible by 400 then
leap year
else if year is divisible by 100 then
not a leap year
else if year is divisible by 4 then
leap year
else
not a leap year

c program for leap year

#include<conio.h>
#include<stdio.h>

int main()
{
    int first, end, leap, leap1, i;
    printf("Enter the starting year ");
    scanf("%d", &first);
    printf("Enter the end year ");
    scanf("%d", &end);
    printf("Leap years between  %d and %d are : \n",first,end);

    if(first>end)                                                        //To check that whether the end year should be greater than first year
    {
         printf("\nEnd year should be greater than starting year\n Enter again : \n");
         scanf("%d", &end);
    }

    for(i=first; i<=end; i++)
    {
         leap=i%4;                                                    //calculation for leap year
         leap1=i%100;
         if(i%400==0)
         {
             printf("%d ",i);
         }
         else if(i%100==0)
         {
         }
         else if(i%4==0)
         {
               printf("%d  ",i);                                  //printing leap year
         }
         else
         {
         }
    }
    getch();
}

Output of c program for leap year:

c program for leap year
c program for leap year

One thought on “c program for leap year”

  1. According to condition ……
    leap1=i%100;

    in output 2000 not considered…….
    2000 is leap year………..
    but output contain 2000

Comments are closed.