Program that Prints the Next 20 Leap Years in C

In this tutorial, you will learn to print the next 20 leap years in c or list of leap year. The initial leap year is entered by the user and also provide number of leap years user want to list down.

To understand this example, you should have the knowledge of the following 

Program that Prints the Next 20 Leap Years in C

#include<stdio.h>
int main() { 
 int n,i;
 printf("\nHow Many Times You Have To Print Leap Year:");
 scanf("%d",&n);
int year;
 printf("\nEnter Leap Year From Which You Want To Print");
 scanf("%d",&year);
 if(year%100==0)
 {
  if(year%400==0)
   {
      printf("%d is Leap Year\n",year);
      printf("LIST OF LEAP YEAR:\n");
      printf("1. %d\n",year);
       for(i=2;i<=n;i++)
       {
year+=4;
printf("%d. %d\n",i,year);
        }
    }
    else
   {
    printf("%d is NOT Leap Year \n Enter Valid Leap Year",year);
   }
}
 else
  if(year%4==0)
  {
   printf("%d is Leap Year\n",year);
   printf("LIST OF LEAP YEAR:\n");
   printf("1. %d\n",year);
    for(i=2;i<=n;i++)
    {
     year+=4;
     printf("%d. %d\n",i,year);
    }
   }
   else
  {
   printf("%d is NOT Leap  Year \n Enter Valid Leap Year",year);
  }
}
return 0;
}

Output


How Many Times You Have To Print Leap Year:5

Enter Leap Year From Which You Want To Print: 2016
2016 is Leap Year
LIST OF LEAP YEAR:
1. 2016
2. 2020
3. 2024
4. 2028
5. 2032
--------------------------------

Share this

0 Comment to "Program that Prints the Next 20 Leap Years in C"

Post a Comment