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 <stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter the year which is to be checked for being leap or not");
scanf("%d",&year);
if (year%4==0 && (year%100!=0 year%400==0))
{
printf("leap year");
}
else
{
printf("not a leap year");
}
getch();
}
Use the following function to determine if a given year is a leap year or not:bool is_leap_year(int year) {
if (year%4) return false;
if (year%100) return true;
if (year%400) return false;
return true;
}
This works by a process of elimination, dealing with the most common cases first:
Years that are not divisible by 4 are not leap years.
Years that are divisible by 4 but not by 100 are leap years.
Years that are divisible by 100 but not by 400 are not leap years.
Years that are divisible by 400 are leap years.
The simplest code for leap year in Java is something like this:
public static boolean isLeapYear(int year) {
return ((year % 4 0);
}
But recommend to use the standard Java library to test for a leap year:
new GregorianCalendar().isLeapYear(year);
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
helicopter
sizeof is your friend.
what is if(!(str[i]==32))
Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.
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
// 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(); }
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
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.
#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(); }
find the program in c-pgms.blogspot.com
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(); }
For first find an example program.
find the area of abc a[2,3] c[6,0]
try this---> http://c-pgms.blogspot.com/2008/08/program-to-find-meanmedianand-mode_22.html
find median of n observation in c program