This program will read value of N and print all Leap Years from 1 to N years. There are two conditions for leap year: 1- If year is divisible by 400 ( for Century years), 2- If year is divisible by 4 and must not be divisible by 100 (for Non Century years).
/*C program to print all leap years from 1 to N.*/
#include <stdio.h>
//function to check leap year
int checkLeapYear(int year)
{
if( (year % 400==0)||(year%4==0 && year%100!=0) )
return 1;
else
return 0;
}
int main()
{
int i,n;
printf("Enter the value of N: ");
scanf("%d",&n);
printf("Leap years from 1 to %d:\n",n);
for(i=1;i<=n;i++)
{
if(checkLeapYear(i))
printf("%d\t",i);
}
return 0;
}
Print all Leap Years from 1 to N using C program
Output
need an explanation for this answer? contact us directly to get an explanation for this answer