第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

c++編程,給出年月日,計(jì)算該日是該年的第幾天?

c++編程,給出年月日,計(jì)算該日是該年的第幾天?

紅糖糍粑 2019-05-23 19:15:15
c++編程,給出年月日,計(jì)算該日是該年的第幾天
查看完整描述

3 回答

?
紅顏莎娜

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊

 

1

#include <iostream>

 

1

using namespace std;

 

1

2

3

4

5

int main()

{

    int sum_day(int month,int day);

    int is_leap(int year);

    int year,month,day,days;

 

1

2

    cout<<"Enter date(for example:2015 1 14):\n";

    cin>>year>>month>>day;

 

1

2

3

    days=sum_day(month,day);

    if(is_leap(year)&&month>2)

        days+=1;

 

1

    cout <<year<<"/"<<month<<"/"<<day<<"is the "<<days<<" day in this year!\n";

 

1

2

    return 0;

}

 

1

2

3

4

5

6

7

8

int sum_day(int month,int day)

{

    int day_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

    int i;

    for(i=1;i<month;i++)

        day+=day_tab[i];

    return day;

}

 

1

2

3

4

5

int is_leap(int year)

{

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

}

我在code blocks上運(yùn)行沒有問題


查看完整回答
反對(duì) 回復(fù) 2019-05-26
?
慕桂英546537

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

#include<iostream>

using namespace std;

int d[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},

              {31,29,31,30,31,30,31,31,30,31,30,31} };

int days(int m,int a=0)

    int sumday=0;

 for(int i=0;i<m-1;++i)

  sumday+=d[a][i];

 return sumday;

}

int main()

{

 int day=0,month=0,year=0;

 cout<<"day   :";cin>>day;

 cout<<"month :";cin>>month;

 cout<<"year  :";cin>>year;

    int a=0;

 //  閏年判斷

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

 switch(month)

 {

 case 1:case 2:

 case 3:case 4:

 case 5:case 6:

 case 7:case 8:

 case 9:case 10:

 case 11:case 12: cout<<days(month,a)+day<<endl;

 default: break;

 }

  

 return 0;

}


查看完整回答
反對(duì) 回復(fù) 2019-05-26
?
互換的青春

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

# include <stdio.h>

# include <conio.h>

int sum_day(int month, int day);

int leap(int year);

void main()

{

int year, month, day;

int days;

printf("請(qǐng)輸入日期(年,月,日):");

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

printf("%d年%d月%d日", year, month, day);

days = sum_day(month, day);

if(leap(year) && month>=3)

days = days + 1;

printf("是該年的第%d天.\n", days);

getch();

}

static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int sum_day(int month, int day)

{

int i;

for(i=1; i<month; i++)

day = day + day_tab[i];

return day;

}

int leap(int year)

{

int leap;

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

return leap;

}

沒調(diào)試過,機(jī)子上暫時(shí)沒工具,應(yīng)該是沒問題了。你試試

查看完整回答
反對(duì) 回復(fù) 2019-05-26
  • 3 回答
  • 0 關(guān)注
  • 2140 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)