C Language Judgment Common year/leap year

Source: Internet
Author: User

Requirements:

After the user enters the year, determine whether the input is common year or leap years


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

Intmain (void)

{

       // Defining Variables

int year = 0;

int temp = 0;

int temp1 = 0;

       // Prompt user to enter year

printf (" Please enter the year:");

scanf ("%d", &year);

       // first determine whether the current year is a whole or a full thousand

temp = year% 100;

       // If the year is full or full thousand, use the - as a divisor

if (temp = = 0)

{

Temp1 = year% 400;

if (Temp1 = = 0)

{

printf ("%d years is a leap year \ n";

}

Else

{

printf ("%d is common year \ n", year);

}

}

Else

{

Temp1 = year% 4;

if (Temp1 = = 0)

{

printf ("%d years is a leap year \ n";

}

Else

{

printf ("%d is common year \ n", year);

}

}

System ("pause");

return 0;

}



C Language Judgment Common year/leap year

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.