当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

重庆邮电大学:《C语言程序设计》作业 2 根据订票的张数和月份决定优惠折扣(谢竞博)

资源类别:文库,文档格式:DOC,文档页数:3,文件大小:33.5KB,团购合买
#include void main() { int month,tickets;/*变量命名要见名知义,不要都用 a,b,c 之类的*/ printf("please input month:"); scanf("%d",&month);
点击下载完整版文档(DOC)

作业2根据订票的张数和月份决定优惠折扣 写法一:用 switch(语句 #include oid main( int month, tickets,/*变量命名要见名知义,不要都用a,b,c之类的*/ printf("please input month scanf(%d",&month) printf(" how many tickets?"),/*输入前的提示要人性化,不要写 please input a这样的字样*/ scanf("%d", tickets) printf("input error!”) switch( month)/*(中只能是变量或者变量构成的算术表达式,而且它们的结果必须是整型 或字符型,这样才能与case后比对* case7:/*case与后边的数据之间要用空格分开* case8:/*case后边只能是结果,不能再是条件,例如:case(7=20这 类的写法是错误的。* case9;/多种case是一种情况,只在最后的case后写明即可,其它可不写。另外,月份 不必按顺序排,一般将出现次数多的case排在前边,好处是比较的效率高*/ if (tickets >=20) printf("10%%off \n") printf("5%%off n") default:/其它多种情况可以放在 default里,就不用一一列举了*/ if ( tickets >=20) int("20%% off \n")严输出%,用 printf(-20%%”) printf("10%%off \n") 也可以写成 #include 12 month<0)

作业 2 根据订票的张数和月份决定优惠折扣。 写法一:用 switch()语句 #include void main() { int month,tickets;/*变量命名要见名知义,不要都用 a,b,c 之类的*/ printf("please input month:"); scanf("%d",&month); printf("how many tickets?"); /*输入前的提示要人性化,不要写 please input a 这样的字样*/ scanf("%d",& tickets); if(tickets12||month=20 这 类的写法是错误的。*/ case 9: /*多种 case 是一种情况,只在最后的 case 后写明即可,其它可不写。另外,月份 不必按顺序排,一般将出现次数多的 case 排在前边,好处是比较的效率高*/ if (tickets >=20) printf("10%%off \n"); else printf("5%%off \n"); break; default:/*其它多种情况可以放在 default 里,就不用一一列举了*/ if (tickets >=20) printf("20%%off \n");/*输出%,用 printf(“20%%”); */ else printf("10%%off \n"); break; } } 也可以写成 #include void main() { int month,tickets;/*变量命名要见名知义,不要都用 a,b,c 之类的*/ printf("please input month:"); scanf("%d",&month); printf("how many tickets?"); /*输入前的提示要人性化,不要写 please input a 这样的字样*/ scanf("%d",& tickets); if(tickets12||month<0)

printI(input error!”) case 1:/*20张票以上的情况* printf("10%%off\n"), break default printf("5%%off n"); break case0:/20张票以下的情况* switch( month) case 7 ase 9 off n"); br default. printf("10%%off \n"), break 写法二:用i-else语句 #include void maino int month. tickets. printf("please input month canf("%d", &month printf("how many tickets? ") scanf("%d", tickets) printi("input error!”) if( month>=7&& month=20) printf("10%%off

printf(“input error!”); else switch (tickets/20) { case 1: /*20 张票以上的情况*/ switch(month) { case 7: case 8: case 9: printf("10%%off\n");break; default: printf("5%%off \n");break; } case 0: /*20 张票以下的情况*/ switch(month) { case 7: case 8: case 9: printf("20%%off \n");break; default: printf("10%%off \n");break; } } } 写法二:用 if-else 语句 #include void main() { int month,tickets; printf("please input month:"); scanf("%d",&month); printf("how many tickets?"); scanf("%d",& tickets); if(tickets12||month=7&&month=20) printf("10%%off ");

else printf("5%%off " else/*其它月份* if(tickets>=20) printf("20%%off"); else printf("io%o%of");/*对于 if-else嵌套,尽量用不同的缩进,这样容易看清楚结构

else printf("5%%off "); } else/*其它月份*/ { if (tickets>=20) printf("20%%off "); else printf("10%%off ");/*对于 if-else 嵌套,尽量用不同的缩进,这样容易看清楚结构。 */ } }

点击下载完整版文档(DOC)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
已到末页,全文结束
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有