编写程序计算某年某月的天数.输入年份year和月份month,输出该月份的天数

Python017

编写程序计算某年某月的天数.输入年份year和月份month,输出该月份的天数,第1张

#include<stdio.h>

int main(){

int year,month

int a=0

printf("输入任意符合范围(1月~12月)的月份和(1900年~9999年)年份,且两个值之间空格分隔。\n")

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

if(year%4==0&&year%100!=0||year%400==0)

a=1//结果为1代表闰年

switch(month){

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

printf("year =%d month =%d days=31\n",year,month)

break

case 2:

if(a==1)

printf("year =%d month =%d days=29\n",year,month)

else

printf("year =%d month =%d days=28\n",year,month)

break

case 4:

case 6:

case 9:

case 11:

printf("year =%d month =%d days=30\n",year,month)

break

}

return 0

}

1.可以用DateDiff函数,返回值表示两个指定日期间的时间间隔。

2.也可以把两个日期直接相减:

a = Now - CDate("2014-1-1") '2014年1月1日到今天,共这么多天。

b = CDate("2014-3-1") - CDate("2014-1-1") '2014年1月1日到2014年3月1日,共这么多天。

vb的函数是强大的,闰年和平年它自己会处理,无需担心。

追问:

那需要什么控件,能详细说一下吗

回答:

不需要任何控件呢,是系统自带的函数呢,你写到代码里面试试就可以了。

你稍等,我给你写代码:

'窗体弄一个按钮Command1,加入以下代码,你试试看:

Private Sub Command1_Click()

Dim a As Long

Dim b As Long

a = Now - CDate("2014-1-1")'2014年1月1日到今天,共这么多天。

b = CDate("2014-3-1") - CDate("2014-1-1")'2014年1月1日到2014年3月1日,共这么多天。

Print "2014年1月1日到今天,共" &a &"天。"

Print "2014年1月1日到2014年3月1日,共" &b &"天。"

End Sub

#include<iostream.h>

void main()

{

  int Year,Month,Day

  cout <<"Please enter the current date(年月以空格分隔):"

  cin >>Year>>Month

  while(Month<=0 || Month>12 )

   {

        cout<<"输入时间有误,请重新输入:"

     cin >>Year>>Month

     }

  switch(Month)

   {

          case 4:

          case 6:

          case 8:

          case 9:

          case 11:

                 Day=30

       break

         case 2:

             if(Year%400 == 0 || Year%4==0 && nYear%100 != 0)

                 Day=29

             else

                 Day=28

      break

   default: Day=31

    }

     cout <<"该月天数为:" << Day <<"天"

   }

尊敬的审核人员,对于您说的排版不清晰问题做出解释:C语言编辑器的自动排版,不能完全左对齐。