第四章:选择结构

2026/1/15 7:47:15

}

else

{ 【3】; printf(“%f”,mon); }

26. 某服装店经营套服,也单件出售。若买的不少于50套,每套80元;不足50

套的每套90元;只买上衣每件60元;只买裤子每条45。以下程序的功能是读入所买上衣c和裤子t的件数,计算应付款m。请在【】内填入正确内容。

27. { }

int y,f;

scanf(“%d”,&y); if(y@0==0) f=1; else if(【1】) f=1; else 【2】;

if(f) printf(“%d is”,y); else

printf(“%d is not”,y);

printf(“a leap year\\n”);

以下程序的功能是判断输入的年份是否是闰年。请在【】内填入正确内容。 main() main() { }

int c,t,m;

printf(“input the number of coat and trousers you want buy:\\n”); scanf(“%d %d”,&c,&t); if(【1】)

if(c>=50) m=c*80; else m=c*90; if(【2】)

if(t>=50) m=t*80+(c-t)*60; else m=t*90+(c-t)*60; if(【3】) m=c*80+(t-c)*45; else m=c*90+(t-c)*45;

else

else

printf(“%d”,m);

28.

以下程序段针对输入的截止日期(年:yend,月:mend,日dend:)和出生日

期(yman,mman,dman),计算出实际年龄。请在【】内填入正确内容。 设有:int yend,mend,dend,yman,mman,dman,age; age=yend-yman;

if(mend【1】mman) age--;

else if(mend【2】mman&&dend【3】dman)

age--;

使用分支语句设计一个程序,要求输入年月日以后,算出这天是这一年的第几

29.

天。运行时输入情况如下:

请输入日期(例如:2005 2 28):2005 2 28 2005年2月28日是2005年的第59天。

提示:注意闰年,四年一润、百年不润、四百年又一润。使用switch语句的时候要注意其break特性,尽量设计出较简洁的代码。 参考程序:

#include void main() {

int year,month,day,n;

printf(\请输入日期(例如:2005 2 28):\

scanf(\ n=day;

switch(month) {

case 12: //如果是12月,要将前11个月的天数加起来,没有break语句,会顺序执行

n+=30;

case 11: //如果是11月,要将前10个月的天数加起来 n+=31;

case 10: //如果是10月,要将前9个月的天数加起来 n+=30; case 9: n+=31; case 8: n+=31; case 7: n+=30; case 6: n+=31; case 5: n+=30; case 4: n+=31; case 3:

if(year%4==0&&year0!=0||year@0==0) n+=29; //闰年2月是29天 else n+=28; //非闰年2月是28天。

case 2: n+=31; }

printf(\年%d月%d日是%d年的第%d天。\\n\}


第四章:选择结构.doc 将本文的Word文档下载到电脑
搜索更多关于: 第四章:选择结构 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219