要求:

用户输入年份之后,判断输入的是平年还是闰年


#include<stdio.h>

#include<stdlib.h>

#include<string.h>

 

intmain(void)

{

       //定义变量

       int year = 0;

       int temp = 0;

       int temp1 = 0;

 

       //提示用户输入年份

       printf("请输入年份:");

       scanf("%d",&year);

 

       //首先判断当前的年份是否为整百或整千

       temp = year % 100;

 

       //如果为整百或整千的年份,使用400作为除数

      

              if(temp == 0)

       {

              temp1 = year % 400;

              if(temp1 == 0)

              {

                     printf("%d年是闰年\n",year);

              }

              else

              {

                     printf("%d年是平年\n",year);

              }

       }

       else

       {

              temp1 = year % 4;

              if(temp1 == 0)

              {

              printf("%d年是闰年\n",year);

              }

              else

              {

                     printf("%d年是平年\n",year);

              }

       }

       system("pause");

       return 0;

}