This blog is under construction

Monday 10 June 2013

C program to check whether the given year is leap year or not

Write a C program to check whether the given year is leap year or not.

A year is leap year
  • If the year value is divisible by 400
  • If the year value is divisible by 4 but not divisible by 100



  /* C program to check whether the given year is leap year or not */
  #include <stdio.h>
  int main() {
        int year;
        printf("Enter ur input for year:");
        /* get year value from the user */
        scanf("%d", &year);

        /* check whether the given year is leap or not */
        if (year % 400 == 0) {
                printf("%d is a leap year\n", year);
        } else if (year % 100 == 0) {
                printf("%d is not a leap  year\n", year);
        } else if (year % 4 == 0) {
                printf("%d is a leap year\n", year);
        } else {
                printf("%d is not a leap year\n", year);
        }
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter ur input for year:100
  100 is not a leap  year
  jp@jp-VirtualBox:~/$ ./a.out
  Enter ur input for year:4004
  4004 is a leap year





See Also:

No comments:

Post a Comment