亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用scanf輸入值的問題

用scanf輸入值的問題

C
星輝銀河 2016-03-26 15:40:45
#include?<stdio.h> #include?<stdbool.h> struct?date { ????int?year; ????int?month; ????int?day; }; int?f(struct?date?d) { ????if(d.month<=2) ????????return?d.year-1; ????else ????????return?d.year; } int?g(struct?date?d) { ????if(d.month<=2) ????????return?d.month+13; ????else ????????return?d.month+1; } int?calculateN(struct?date?d) { ????int?N; ????N=1461*f(d)/4+153*g(d)/5+d.day; ????return?N; } int?calculateDay(struct?date?d1,struct?date?d2) { ????int?day,d1N,d2N; ????d1N=calculateN(d1); ????d2N=calculateN(d2); ????day=d1N-d2N; ????if(day<0) ????????day=-day; ????return?day; } int?main(void) { ????struct?date?d1,d2; ????printf("Please?enter?two?date(YYYY?MM?DD):?\n"); ????printf("The?first:?"); ????scanf("%i?%i?%i",&d1.year,&d1.month,&d1.day); ????printf("\nThe?second:?"); ????scanf("%i?%i?%i",&d2.year,&d2.month,&d2.day); ????printf("\nThe?day?between?the?two?date?is:?%i",calculateDay(d1,d2)); ????printf("\n?%i?%i",calculateN(d1),calculateN(d2)); ???? ????return?0; }這里我輸入第一個日期輸入2004 08 08時,d1.year=2004, d1.month=0, d1.day=8,而第二個日期輸入2005 02 02時,d2.year=0, d2.month = 8, d2.day=2005,請問這些日期錯亂和變成0是怎么回事呢?
查看完整描述

1 回答

?
qq___524

TA貢獻171條經驗 獲得超74個贊

把scanf的占位符改成%d就行了

%i 是老式寫法,都是整型格式,i %表示 integer 表示整型值,默認為十進制數表示,
d %表示 decimal 明確地表明了這是一個十進制數表示。

查看完整回答
反對 回復 2016-03-27
  • 1 回答
  • 0 關注
  • 1574 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號