真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

c語言用函數(shù)計算天數(shù) 計算天數(shù)c語言pta

c語言 用庫函數(shù)計算兩日期相差的天數(shù)

#include?stdio.h

成都創(chuàng)新互聯(lián)公司成都企業(yè)網(wǎng)站建設服務,提供成都網(wǎng)站設計、成都做網(wǎng)站網(wǎng)站開發(fā),網(wǎng)站定制,建網(wǎng)站,網(wǎng)站搭建,網(wǎng)站設計,成都響應式網(wǎng)站建設公司,網(wǎng)頁設計師打造企業(yè)風格網(wǎng)站,提供周到的售前咨詢和貼心的售后服務。歡迎咨詢做網(wǎng)站需要多少錢:18980820575

#include?stdlib.h

#include?string.h

#include?math.h

#include?time.h

int??get_days(const?char*?from,?const?char*?to);

time_t?convert(int?year,int?month,int?day);

int?main()

{

const?char*?from="2013-3-15";

const?char*?to="2015-8-14";

int?days=get_days(from,to);

printf("From:%s\nTo:%s\n",from,to);

printf("%d\n",days);

return?0;

}

time_t?convert(int?year,int?month,int?day)

{

struct?tm?info={0};

info.tm_year=year-1900;

info.tm_mon=month-1;

info.tm_mday=day;

return?mktime(info);

}

int??get_days(const?char*?from,?const?char*?to)

{

int?year,month,day,fromSecond,toSecond;

sscanf(from,"%d-%d-%d",year,month,day);

fromSecond=(int)convert(year,month,day);

sscanf(to,"%d-%d-%d",year,month,day);

toSecond=(int)convert(year,month,day);

return?(toSecond-fromSecond)/24/3600;

}

From:2013-3-15

To:2015-8-14

882

Press?any?key?to?continue

這才算是用了庫函數(shù)了···

急求!C語言計算天數(shù)

#includestdio.h

int main()

{

int yyyy,mm,dd,a,b;

scanf("%d/%d/%d",yyyy,mm,dd);

a=31*(mm1)+28*(mm2)+31*(mm3)+30*(mm4)+31*(mm5)+30*(mm6)+31*(mm7)+31*(mm8)+30*(mm9)+31*(mm10)+30*(mm11)+dd;

b=((yyyy%4==0)*(yyyy%100!=0)+(yyyy%400==0))*(mm2);

printf("%d\n",a+b);

return 0;

}

C語言編程:定義一個結構體用于存儲年、月、日數(shù)據(jù),并定義一個函數(shù)用于求兩個日期之間的天數(shù)。

#include?stdio.h

const?int?days[13]?=?{0,?31,?28,?31,?30,?31,?30,?31,?31,?30,?31,?30,?31};

struct?Date

{

int?year,?month,?day;

};

int?DateCmp(Date?a,?Date?b)

{

if?(a.year?!=?b.year)

return?a.year??b.year;

if?(b.month?!=?a.month)

return?a.month??b.month;

return?a.day??b.day;

}

int?isLunar(int?year)

{

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

}

int?DateDistace(Date?a,?Date?b)

{

if?(DateCmp(a,?b))//保證a小于b

{

Date?t?=?b;

b?=?a;

a?=?t;

}

//計算結果存儲在res中

//首先計算相差的年

int?i?=?a.year?+?1,?j?=?b.year?-?1,?res?=?a.year?==?b.year???0?:?(j?-?i?+?1)?*?365;

for?(int?ii?=?(i?+?3)?/?4?*?4,?jj?=?j?/?4?*?4;ii?=?jj;ii?+=?4,?res++);

for?(int?ii?=?(i?+?99)?/?100?*?100,?jj?=?j?/?100?*?100;ii?=?jj;ii?+=?100,?res--);

for?(int?ii?=?(i?+?399)?/?400?*?400,?jj?=?j?/?400?*?400;ii?=?jj;ii?+=?400,?res++);

//然后計算相差的月

if?(a.year?!=?b.year)

{

for?(int?ii?=?a.month?+?1;ii?=?12;ii++)

res?+=?ii?==?2???28?+?isLunar(a.year)?:?days[ii];

for?(int?ii?=?1;ii?=?b.month?-?1;ii++)

res?+=?ii?==?2???28?+?isLunar(b.year)?:?days[ii];

}

else

{

for?(int?ii?=?a.month?+?1;ii??b.month;ii++)

res?+=?ii?==?2???28?+?isLunar(a.year)?:?days[ii];

}

//最后計算相差的日

if?(a.year?!=?b.year?||?a.month?!=?b.month)

{

res?+=?(a.month?==?2???28?+?isLunar(a.year)?:?days[a.month])?-?a.day?+?b.day;

}

else

{

res?+=?b.day?-?a.day;

}

return?res;

}

int?main()

{

Date?a,?b;

a.year?=?2000;?a.month?=?12;?a.day?=?31;

b.year?=?1000;?b.month?=?1;?b.day?=?1;

printf("%d\n",?DateDistace(b,?a));

return?0;

}

用c語言編寫一個函數(shù),功能是算出每個月的天數(shù)

int?GetMonthDays(int?year,int?month)

{

switch(month)

{

case?1:

case?3:

case?5:

case?7:

case?8:

case?10:

case?12:

return?31;

break;

case?4:

case?6:

case?9:

case?11:

return?30;

break;

case?2:

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

{

return?29;

}

else

{

return?28;

}

break;

default:

printf("month?error!");

return?0;

break;

}

}


分享文章:c語言用函數(shù)計算天數(shù) 計算天數(shù)c語言pta
文章轉載:http://weahome.cn/article/dojjecd.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部