google search

Popular Posts


Welcome to BCA Notes

>>>>>>>>>>>>>>>>

Visitors

Search This Blog

Blogger templates

Visitor Map


Sunday, 19 January 2014

Source Code to Check Leap Year

Source Code to Check Leap Year



/* C program to check whether a year is leap year or not using if else statement.*/

#include <stdio.h>
int main(){
      int year;
      printf("Enter a year: ");
      scanf("%d",&year);
      if(year%4 == 0)
      {
          if( year%100 == 0) /* Checking for a century year */
          {
              if ( year%400 == 0)
                 printf("%d is a leap year.", year);
              else
                 printf("%d is not a leap year.", year);
          }
          else
             printf("%d is a leap year.", year );
      }
      else
         printf("%d is not a leap year.", year);
      return 0;
}
Output 1


Enter year: 2000
2000 is a leap year.
Output 2


Enter year: 1900
1900 is not a leap year.
Output 3


Enter year: 2012
2012 is a leap year.

0 comments:

Post a Comment