LEAP YEAR:-if the year is divisible by 4 that year is leap year and the year is divisible by 100 which gives remainder 0 then that year is not a leap year.......
#include<stdio.h>
#include<conio.h>
int main()
{
int year, decided;
printf("Enter the Year");
scanf("%d"&year);
decided= 0;
if (year%4!=0) decided= -1; /* ordinary year, eg 1901 */
if (!decided && year%100!=0) decided= 1; /* leap year, eg 1904 */
if (!decided && year%400!=0) decided= -1; /* ordinary year, eg 1900 */
if (!decided) decided= 1; /* leap year, eg 2000 */
if (decided<0) printf("Year is not Leap Year");
else printf ("Leap Year");
return 0;
}
it can can solve by this Easy method
#include<stdio.h>
#include<conio.h>
void main()
{
int year, lyear;
printf("Enter the year = ");
scanf("%d",&year);
lyear=year%4;
if(lyear==0)
{
printf("Leap year");
}
else
{
printf("Not a Leap year");
}
getch();
}
Below is a program; not completely bullet proof - allows negative years! #include <stdio.h> #define true 1
#define false 0 void main(int argc, char *args[])
{
int year; if(argc !=2)
{
printf("Usage:\n\n%s <year>\n",args[0]);
exit(0);
}
year = atoi(args[1]);
if (IsLeap(year))
printf("%d is a leap year.",year);
else
printf("%d is not a leap year.",year);
} int IsLeap(int year) {
int Result; if (year % 400 0)
{
Result = true;
}
else
{
Result = false;
}
}
}
return Result;
}
If the year divides evenly by 4 it's a leap year. If it's a century year it has to divide evenly by 400. 2000 was a leap year. 2100 will not be a leap year.
3900
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
// leap year by @bhi// #include<stdio.h> #include<conio.h> void main() { int year; clrscr(); printf("Enter the Year that you want to check : "); scanf("%d", &year); if(year % 400 == 0) printf("%d is a Leap Year.", year); else if(year % 100 == 0) printf("%d is not a Leap Year.", year); else if(year % 4 == 0) printf("%d is a Leap Year.", year); else printf("%d is not a Leap Year", year); printf("\nPress any key to Quit..."); getch(); }
int isleap(int year) {return year % 4 0 && year % 400 != 0);}The rule is that years divisible by 4 are leap, except that century years not divisible by 400, such as 2100, are not leap. The question stated a range of 2000 to 2500, so the answer does not address non Gregorian calendars or the shift between Julian and Gregorian.
Algorithm: If the year is not divisible by 4 then it is not a leap year. Else if the year is not divisible by 100 then it is a leap year. Else if the year is not divisible by 400 then is not a leap year. Else it is a leap year. Implementation: bool is_leap_year (unsigned year) { if (year%4) return false; if (year%100) return true; if (year%400) return false; return true; }
#include #include void main() { int y; clrscr(); print f ("enter a year"); scan f ("%d",&y) (y%100==0):((y%400==0)?print f("% d is leap year",y):print f("%d is not leap year",y):((y%4==0)? print f ("d is leap year",y): print f ("%d is leap year",y): print f ("%d is not leap year,y)); getch(); }
leap yr = ((y%100!=0 && yr %400==0)?1:(yr%4==0)?1:0; leap yr =1; printf ("leap yr"); else printf ("not leap yr");
You can use a number of nested "if" commands. The rules are the following: If the year is a multiple of 400, it IS a leap year. Else, if the year is a multiple of 100, it's NOT a leap year. Else, if the year is a multiple of 4, it IS a leap year. Else it's NOT a leap year. In Java, to check for divisibility, you use the "%" operator, which gives you the remainder of a division. For example: if (year % 400 = 0) ... To show results on screen, you use: System.out.println(...)
3080 will be a leap year.
1776 was a leap year
No. If the year number can be divided by four then it's a leap year. 2012=Leap year.