Talk C Chestnut Bar (second time: C-language instance-judging leap years)

Source: Internet
Author: User


Crossing, everyone, from today onwards, we talk about the large-scale couplet science fiction: C Chestnut, that is, C language examples. Gossip Hugh,

Words return to the positive turn. Let's talk about C language examples together!


Crossing, the last time we gave the novel an opening, this time we formally say the C example, this time to say the example is: to judge leap years.

Crossing, what is a leap year? This is the concept of geographical astronomy. If you do not understand, you go to Baidu, haha. I also stole a lazy.


Crossing, there are two ways to judge a leap year:

    • If a year can be divisible by 4, but not divisible by 100, then this year is leap years.
    • If the year can be divisible by 400, then this year is leap years.


Crossing see divide must think of division, in fact, the division in the C Program and Math division operation is not the same, C Program Division Transport

Only integers are taken, and decimals after the decimal point are discarded. For example: 5/3=1.666 .... This is the result of a mathematical operation, the result of a C program

is 1 because it discards 1 of the number of decimal parts behind it. So we can't use the division operation to judge leap years. How to judge? Crossing Mo Urgent.

In the C program provides the take-up operation, the operation symbol is%. The residual operation is to take out the remainder in the division operation. For example: 5/3 of the remainder is 2.

So the result of the 5%3 is 2. Let's think, what does this mean if the result of the operation is 0 after taking a number for the remainder operation?

"This means that the number can be divisible by another number." This crossing is right. For example, 4%2=0 can indicate that 4 can be divisible by 2. See

Officials, the words are here, and now you know how to judge a leap year.


Crossing, the text does not write code, detailed code in my resources, you can click on this link to download the use.


Crossing, we're going to talk about this in the case of a leap year. I want to know what the following example, and listen to tell.

Talk C Chestnut Bar (second time: C-language instance-judging leap years)

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.