Tuesday, September 4, 2018

12. WAP to determine whether a year is a leap year or not - METHOD 1.

#include <stdio.h>
#include<conio.h>
int main()
{
   int yr;
   printf("Enter a year: ");
   scanf("%d",&yr);
   if(yr%4==0)
   {
      if(yr%100==0)
      {
        if(yr%400==0) //yr is divisible by 400 => it is a (century) leap year
        {
          printf("%d is a leap year.", yr);
         }
         else
         {
          printf("%d is not a leap year.", yr);
         }
      }
      else
      {
         printf("%d is a leap year.", yr);
      }
   }
   else
   {
printf("%d is not a leap year.", yr);
   }
   getch();
}


OUTPUT:



Please have a look at the below video lesson posted on my YouTube channel:


No comments:

Post a Comment