C language to determine whether a year is a leap years of various implementation program code

Source: Internet
Author: User

The introduction of this article:C language to determine whether a year is a leap years of various implementation program code 1, the Gregorian Leap year calculation principle (according to a regression years 365 days 5 hours 48 minutes 45.5 seconds) 1) ordinary year can divide 4 and cannot divide 100 into leap years. (such as 2004 years is a leap year, 1900 is not a leap year) 2) century can divide 400 is leap years. (such as 2000 is a leap year ...)

C language to determine whether a year is a leap years of various implementation program code

1. The Gregorian leap year calculation principle (according to a regression years 365 days 5 hours 48 minutes 45.5 seconds)

1) The average year can be divisible by 4 and not divisible by 100 for leap years. (For example, 2004 is a leap year, 1900 is not a leap)

2) century can be divisible by a leap year. (as 2000 is a leap year, 1900 is not a leap year)

3) for a large number of years, if the year can be divisible by 3200, and can be divisible by 172800 is a leap. If 172,800 is a leap year, 86,400 years is not a leap year (because it can be divisible by 3200, but not divisible by 172800) (this is calculated by a regression of 365 days 5h48 ' 45.5 ").

2, the Gregorian leap year program judgment statement

if ((0 = = year%4) && (0! = year%100)) | | (0 = = year%400))

{

The yeat that satisfy this condition are leap years.

}

3, the Gregorian Leap Year program code (by www. 169it. COM collected from the Internet )

Gregorian leap Year implementation code one:

123456789101112131415161718192021 #include <stdio.h>void main(){ int year,leap; scanf("%d",&year); if(year%4==0) {  if(year%100!=0)   leap=1;  else  {   if(year%400==0)    leap=1;   else    leap=0;  } } if(leap==1)  printf("%d是闰年n",year); else  printf("%d不是闰年n",year);}

Gregorian leap Year implementation code two:

12345678910 #include <stdio.h>void main(){ int year,leap; scanf("%d",&year); if(year%400==0||year%4==0&&year%100!=0)  printf("%d是闰年n",year); else  printf("%d不是闰年n",year);}

Gregorian leap Year implementation code three:

12345678910111213141516 #include<stdio.h>int main(){int year;year=1900;while(year<=2000){if(year%400==0||year%4==0&&year%100!=0){printf("%d是闰年n",year);year++;}else year++;}return 0;}

The above code is for reference only.

C language to determine whether a year is a leap years of various implementation program code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.