.

.

Wednesday

C program to check leap year



The logic of leap year is that, a years which is perfectly divisible by 4 but not by 100 is leap year but a year which is divisible by both 100 and 4,then it can be a leap year if it is divisible by 400.

Here is the C programming code to check whether it is leap year or not.To run this programming just copy the 
bellow code and pest it on turbo c or any else application you use :

#include <stdio.h>

#include <conio.h>

void main()

{

 int y;
  printf("Enter a year to check if it is a leap year\n");

  scanf("%d", &y);

  if ( y%400 == 0)

  printf("%d is a leap year.\n", y);

  else if ( y%100 == 0)

  printf("%d is not a leap year.\n", y);

  else if ( y%4 == 0 )

  printf("%d is a leap year.\n", y);

  else

  printf("%d is not a leap year.\n", y);


  getch();

}

The Output of this program will look like this :





If you have any more thoughts and query about this post please comment

No comments:

Post a Comment