码迷,mamicode.com
首页 > 编程语言 > 详细

c语言判断平年/闰年

时间:2015-03-17 12:39:47      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:c语言   循环   平年   闰年   

要求:

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


#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;

}



c语言判断平年/闰年

标签:c语言   循环   平年   闰年   

原文地址:http://ronray.blog.51cto.com/1434167/1621342

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!