程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> c語言---簡易日期加1天系統

c語言---簡易日期加1天系統

編輯:關於C語言

 

考試要用,就寫了,,,有同樣需求的朋友拿走吧。

 

 

#include <stdio.h>

 

 

void main()                              //定義日期部分函數

 

 

{

       char tmps;

       do

       {

              printf("請輸入一個日期(年 月 日)");

 

 

              int year,month,day,tmp;

 

 

              scanf("%d %d %d",&year,&month,&day);

 

 

              if(year < 1000 || year > 9999)             //判斷年份

              {

 

 

                     printf("年輸入的不對,請輸入4位正整數");

 

 

              }

              else if(month > 12 || month < 1)           //判斷月份

              {

 

 

                     printf("月輸入的不對,請輸入1-12的正整數");

 

 

              }

              else

              {

 

 

                     switch(month)                          //定義每個月的天數

                     {

 

 

                     case 1 :

                            tmp = 31;

                            break;

 

 

                     case 2:

                            tmp = 28;

                            break;

 

 

                     case 3 :

                            tmp = 31;

                            break;

 

 

                     case 4:

                            tmp = 30;

                            break;

 

 

                     case 5 :

                            tmp = 31;

                            break;

                     case 6 :

                            tmp = 30;

                            break;

 

 

                     case 7 :

                            tmp = 31;

                            break;

 

www.2cto.com

                     case 8:

                            tmp = 31;

                            break;

 

 

                     case 9 :

                            tmp = 30;

                            break;

 

 

                     case 10:

                            tmp = 31;

                            break;

 

 

                     case 11 :

                            tmp = 30;

                            break;

 

 

                     case 12:

                            tmp = 31;

                            break;

 

 

                     }

 

 

                     if(day == tmp)                //判斷是否為最後一日

                     {

                            printf("後一天的日期為%d %d 1 \n\n",year,month+1);

                     }

                     else if(day == tmp && month == 12)   //判斷是否為最後一個月的最後一天

                     {

                            printf("後一天的日期為%d 1 1 \n\n",year+1);

                     }

                     else

                     {

                            printf("後一天的日期為%d %d %d \n\n",year,month,day+1);

                     }

              }

              printf("繼續嗎?(y/n) ");

              scanf("%s",&tmps);

 

 

       }while(tmps == 'y');

 

 

 

 

}

摘自:Str1ven's Blog

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved