Friday, 14 October 2016

Write a C Program to Find Whether the Given Year is a Leap Year or not.

Exercise - 3 Control Flow - I

a)Aim:-Write a C Program to Find Whether the Given Year is a Leap Year or not.

Program:-
#include <stdio.h>
int main()
{
  int year;
  printf("Enter a year to check if it is a leap year\n");
  scanf("%d", &year);
  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);
}


No comments:

Post a Comment