资源描述:
《c-c 语言趣味程序设计编程百例精解(2)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C-C语言趣味程序设计编程百例精解(2)涓浗鏈夊彞淇楄鍙€滀笁澶╂墦楸间袱澶╂檼缃戔€濄€傛煇浜轰粠1990骞?鏈?鏃ヨ捣寮€濮嬧€滀笁澶╂墦楸间袱澶╂檼缃戔€濓紝闂繖涓汉鍦ㄤ互鍚庣殑鏌愪竴澶╀腑鏄€滄墦楸尖€濊繕鏄€滄檼缃戔€濄€?*闂鍒嗘瀽涓庣畻娉曡璁?鏍规嵁棰樻剰鍙互灏嗚В棰樿繃绋嬪垎涓轰笁姝ワ細1)璁$畻浠?990骞?鏈?鏃ュ紑濮嬭嚦鎸囧畾鏃ユ湡鍏辨湁澶氬皯澶╋紱2)鐢变簬鈥滄墦楸尖€濆拰鈥滄檼缃戔€濈殑鍛ㄦ湡涓?澶╋紝鎵€浠ュ皢璁$畻鍑虹殑澶╂暟鐢?鍘婚櫎锛?3)鏍规嵁浣欐暟鍒ゆ柇浠栨槸鍦ㄢ€滄墦楸尖€濊繕鏄湪鈥滄檼缃戔€濓紱鑻?浣欐暟涓?锛?锛
2、?锛屽垯浠栨槸鍦ㄢ€滄墦楸尖€?鍚﹀垯鏄湪鈥滄檼缃戔€?鍦ㄨ繖涓夋涓紝鍏抽敭鏄涓€姝ャ€傛眰浠?990骞?鏈?鏃ヨ嚦鎸囧畾鏃ユ湡鏈夊灏戝ぉ锛岃鍒ゆ柇缁忓巻骞翠唤涓槸鍚︽湁闂板勾锛屼簩鏈堜负29澶╋紝骞冲勾涓?8澶┿€傞棸骞寸殑鏂规硶鍙互鐢ㄤ吉璇彞鎻忚堪濡備笅锛?濡傛灉((骞磋兘琚?闄ゅ敖涓?涓嶈兘琚?00闄ゅ敖)鎴?鑳借400闄ゅ敖)鍒?璇ュ勾鏄棸骞达紱鍚﹀垯涓嶆槸闂板勾銆?C璇█涓垽鏂兘鍚︽暣闄ゅ彲浠ヤ娇鐢ㄦ眰浣欒繍绠?鍗虫眰妯?*绋嬪簭璇存槑涓庢敞閲?#includeintdays(structdateday);structda
3、te{intyear;intmonth;intday;};intmain(){structdatetoday,term;intyearday,year,day;printf("Enteryear/month/day:");scanf("%d%d%d",&today.year,&today.month,&today.day);/*杈撳叆鏃ユ湡*/term.month=12;/*璁剧疆鍙橀噺鐨勫垵濮嬪€硷細鏈?/term.day=31;/*璁剧疆鍙橀噺鐨勫垵濮嬪€硷細鏃?/for(yearday=0,year=1990;year4、r=year;yearday+=days(term);/*璁$畻浠?990骞磋嚦鎸囧畾骞寸殑鍓嶄竴骞村叡鏈夊灏戝ぉ*/}yearday+=days(today);/*鍔犱笂鎸囧畾骞翠腑鍒版寚瀹氭棩鏈熺殑澶╂暟*/day=yearday%5;/*姹備綑鏁?/if(day>0&&day<4)printf("hewasfishingatthatday.");/*鎵撳嵃缁撴灉*/elseprintf("Hewassleepingatthatday.");}intdays(structdateday){staticintday_tab[2][13]={{0,31,28,31,30
5、,31,30,31,31,30,31,30,31,},/*骞冲潎姣忔湀鐨勫ぉ鏁?/{0,31,29,31,30,31,30,31,31,30,31,30,31,},};inti,lp;lp=day.year%4==0&&day.year%100!=0
6、
7、day.year%400==0;/*鍒ゅ畾year涓洪棸骞磋繕鏄钩骞达紝lp=0涓哄钩骞达紝闈?涓洪棸骞?/for(i=1;i8、y:19911025Hewasfishingatday.Enteryear/month/day:19921025Hewassleepingatday.Enteryear/month/day:19931025Hewassleepingatday.*鎬濊€冮璇锋墦鍗板嚭浠绘剰骞翠唤鐨勬棩鍘?12.鎶撲氦閫氳倗浜嬬姱涓€杈嗗崱杞﹁繚鍙嶄氦閫氳鍒欙紝鎾炰汉鍚庨€冭窇銆傜幇鍦烘湁涓変汉鐩嚮浜嬩欢锛屼絾閮芥病鏈夎浣忚溅鍙凤紝鍙涓嬭溅鍙风殑涓€浜涚壒寰併€傜敳璇达細鐗岀収鐨勫墠涓や綅鏁板瓧鏄浉鍚岀殑锛涗箼璇达細鐗岀収鐨勫悗涓や綅鏁板瓧鏄浉鍚岀殑锛屼絾涓庡墠涓や綅涓嶅悓锛?涓欐槸
9、鏁板瀹讹紝浠栬锛氬洓浣嶇殑杞﹀彿鍒氬ソ鏄竴涓暣鏁扮殑骞虫柟銆傝鏍规嵁浠ヤ笂绾跨储姹傚嚭杞﹀彿銆?*闂鍒嗘瀽涓庣畻娉曡璁?鎸夌収棰樼洰鐨勮姹傞€犲嚭涓€涓墠涓や綅鏁扮浉鍚屻€佸悗涓や綅鏁扮浉鍚屼笖鐩镐簰闂村張涓嶅悓鐨勬暣鏁帮紝鐒跺悗鍒ゆ柇璇ユ暣鏁版槸鍚︽槸鍙︿竴涓暣鏁扮殑骞虫柟銆?*绋嬪簭璇存槑涓庢敞閲?#include#includeintmain(){inti,j,k,c;for(i=1;i<=9;i++)/*i:杞﹀彿鍓