第3章 控制结构与语句.ppt

/*例:求从1月1日到某月某日的天数*/ #include stdio.h main() { int year,month,day,d; printf(Enter year/month/day:); scanf(%d/%d/%d,year,month,day); d=day; switch(month-1) { case 12: d+=31; case 11: d+=30; case 10: d+=31; case 9: d+=30; case 8: d+=31; case 7: d+=31; case 6: d+=30; case 5: d+=31; case 4: d+=30; case 3: d+=31; case 2: if((year%4==0year%100!=0)||(year%400==0)) d+=29; else d+=28; case 1: d+=31; } printf(%d\n,d); } 例: main() {int x=1,y=0,a=0,b=0; switch(x) { case 1: switch(y) { case 0:a++;break; case 1:

文档评论(0)

1亿VIP精品文档

相关文档