Write a program to print the number of leap years in the given list of years.
Input:
First line of input is total number of years (n)
Next n lines will be the years.
#define MAX_YEARS 100
// Return if year is leap year or not.
bool isLeap(int y)
{
if (y%100 != 0 && y%4 == 0 || y %400 == 0)
return true;
return false;
}
main(void)
{
int x,r,n,Years[MAX_YEARS],l=0;
printf("\n\tEnter no. of years: "); scanf("%d",&n);
for(r=0;r<n;r++)
{
printf("\n\tEnter Year-%d: ",r+1); scanf("%d",&Years[r]);
if(isLeap(Years[r])) {l=l+1; printf("\t\tYear %d is a leap year.",Years[r]);}
}
printf("\n\n\Total no. of leap years = %d",l);
}
Comments
Leave a comment