0
Write a C programme that prints the next 20 leap years.
I can't understand, how I start this problem :")
5 Answers
+ 7
Regardless of programming language, you need to know how to determine leap years. There is a simple mathematical formula for it. Check under "Gregorian calendar" on wikipedia.
https://en.m.wikipedia.org/wiki/Leap_year
+ 1
Thanks, for your opinion...
I know this how I check a year which is leap year or not. But, I want to print next 20 leap years.How, I solve this problem..?
+ 1
Start checking each number (starting this year or next year)
If it is a leap year, print it
If you have found 20 already, finish the program
Move on to the next number.
You can use a while loop, and an int variable to count how many years you found.
If you know the formula then the rest is very simple, just put it into code. If you are still stuck, then post what you have tried so far.
+ 1
Yeah. Thanks a lot Martin Taylor .
0
Is this code correct ?
#include<stdio.h>
int main()
{
int i,yr;
printf("Enter year: ");
scanf("%d",&yr);
for(i=1;i<=20;)
{
if(yr%4==0 || yr%400==0 && yr%100==0)
{
printf("%d is a leap year\n",yr);
i++;
}
yr+=1;
}
return 0;
}