实验1-顺序和分支结构题目及参考 答案

上传人:suns****4568 文档编号:88919986 上传时间:2019-05-13 格式:PDF 页数:11 大小:456.53KB
返回 下载 相关 举报
实验1-顺序和分支结构题目及参考 答案_第1页
第1页 / 共11页
实验1-顺序和分支结构题目及参考 答案_第2页
第2页 / 共11页
实验1-顺序和分支结构题目及参考 答案_第3页
第3页 / 共11页
实验1-顺序和分支结构题目及参考 答案_第4页
第4页 / 共11页
实验1-顺序和分支结构题目及参考 答案_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《实验1-顺序和分支结构题目及参考 答案》由会员分享,可在线阅读,更多相关《实验1-顺序和分支结构题目及参考 答案(11页珍藏版)》请在金锄头文库上搜索。

1、实验实验 1 顺序、分支顺序、分支结构结构 程序填空程序填空 1. 本题分值:本题分值:1010 题目描述题目描述:输入三个整数存放在变量 a、b、c 中,找出三个数中的最大值放于 max 中,并 将其输出。以下是完成此项工作的程序,请将未完成的部分填入,实现其功能,并在计算机 上调试程序,以测试填入的部分是否正确。 代码:代码: #include using namespace std; int main() int a,b,c,max; /声明四个整型变量 cinabc; if (ab) max=a; else max=_(1)_; /将a和b中的较大值记录在max中 if (_(2)_

2、max) max=c; /如果c是最大值 cout #include using namespace std; int main() double a,b,c,s,area; /输入三角形的面积a,b,c cinab_(1)_; s=_(2)_; area=sqrt(s*(s-a)*(s-b)*(s-c); /函数sqrt()用来计算一个非负数的平方根,使用这个函数, 需要在源程序中增加“#include“ cout using namespace std; int main( ) int n,ge,shi,bai,qian; /个,十,百,千位: ge,shi,bai,qian cinn;/

3、输入一个不多于 4 位的正整数 if (n=10000 (3) /1000 4. 本题分值:本题分值:1010 题目描述题目描述:在屏幕上显示一张中文时间表,用户根据提示从中选择,程序应根据用户的选择 输出相应的英文问候信息。以下是完成此项工作的程序,请将未完成的部分填入,实现其功 能,并在计算机上调试程序,以测试填入的部分是否正确。 代码:代码: #include using namespace std; int main( ) int n; coutn; /用户输入 1,2 或 3 switch ( _(1)_ ) case 1: cout using namespace std; int

4、 main( ) int year; /存款期限 double money,rate=0,total; /money:本金,rate:月利率,total:本利合计 /输入本金和期限(1,2,3,5 或 8 年) cinmoneyyear; switch( _(1)_ ) case 1: rate=0.0033; break; /期限一年的月利率 case 2: rate=0.0036; break; case 3: rate=0.0039; break; case 5: rate=0.0045; break; case 8: rate=0.0054; break; default: cout

5、using namespace std; int main() int y,m,d; cinym; if(y=3000 | m12) cout using namespace std; int main() int a,b,c,d,s=0; cinabcd; s=a+b+c+d; if(a=60 int main() double tbike,twalk; int distance; cindistance; /输入一次办事要行走的距离输入一次办事要行走的距离 tbike=27+23+distance/3.0; twalk=distance/1.2; if (twalk=tbike) cout

6、。 输入描述:输入描述:输入停车的时间 t。 输出描述:输出描述:输出应该收取的停车费用 cost,保留小数点后 2 位。 样例输入:样例输入:3.46 样例输出:样例输出:5.92 #include #include using namespace std; int main() double t,cost; cint; if(t3 cout using namespace std; int main() double a,b; char c; cinabc; switch(c) case +: cout using namespace std; int main() int n,a,b,c,d,flag=1; coutn; if(n #include using namespace std; int main() int a1,a2,a3,c,s,p,t; couta1a2a3; if(a1+a2 using namespace std; int main() char n; int a; coutn; if(n=0 int main() int a,b,c; coutabc; if(a=b else if(a=b|b=c|c=a) cout“1“endl; else cout“0“endl; return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号