Tuesday, September 4, 2018

13. WAP to determine whether a year is a leap year or not - METHOD 2.

#include <stdio.h>
#include<conio.h>
int main()
{
   int yr;
   printf("Enter a year: ");
   scanf("%d",&yr);
   if(yr%400==0) //exactly divisible by 400 e.g. 1600, 2000
        printf("%d is a leap year \n", yr);
   else if(yr%100==0) //exactly divisible by 100 and not by 400 e.g. 1700, 1900
        printf("%d is a not leap year \n", yr);
   else if(yr%4==0) //exactly divisible by 4 but neither by 100 nor by 400 e.g. 2004, 2016
        printf("%d is a leap year \n", yr);
   else
        printf("%d is not a leap year \n", yr);
   getch();
}


OUTPUT:





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










No comments:

Post a Comment