c程序设计第四版答案

您所在的位置:网站首页 韩国喜剧电影二十 c程序设计第四版答案

c程序设计第四版答案

#c程序设计第四版答案| 来源: 网络整理| 查看: 265

只给出一些需要编程的答案,用的是谭浩强老师的书: 本文持续更新中… C程序设计课本中的一些笔记见:C程序设计笔记

我的目录 只给出一些需要编程的答案,用的是谭浩强老师的书:本文持续更新中...C程序设计课本中的一些笔记见:[C程序设计笔记](https://blog.csdn.net/Mr_Cat123/article/details/84856729) 第一单元6,编写一个c程序,输入a,b,c三个值,输出其中最大者 第二单元2.1 什么是算法,试从日常生活中找出2个例子,描述它们的算法2.2 什么是结构化的算法,为什么要提倡结构化的算法2.6 用伪代码表示第4题中各题的算法 第三单元3.1 假如我国国民生产总值的年增长率为9%,计算10年后我国国民生产总值与现在相比增长多少百分比。计算公式为:3.2 存款利息的计算。现有1000元,想存5年,有五种办法。每种办法得到的结果分别为: 补充:3.3 多少个月还完贷款。 补充:3.4 分析下面的程序 分析:3.5用下面的scanf函数输入数据,。。。。。3.6 请编程序将。。。3.7 设圆半径r=1.5.。。。。 注意:上面代码是3.0/4.0不是3/4,后者是0 第四单元4.1 什么是算术运算?什么是关系运算?什么是逻辑运算?4.3 写出下面各逻辑表达式的值。设a=3,b=4,c=5.4.4 3个整数,键盘输入,求最大值4.5 从键盘输入一个小于1000的正数,要求输出它的平方根。。。。4.7 有一函数:。。。4.8 给出一百分制成绩,要求输出成绩等级。。。。4.9 给一个不多于5位的正整数,要求:...4.10 企业发放的奖金。。。4.11 输入4个。。。4.12 有4个圆塔。。。 第五单元5.2 请补充5.7程序....5.4 请输入一行字符,分别统计其中英文字母,空格,数字和其他字符的个数。5.5 求$S_n=a+aa+aaa+aaaa+aaaaa...$,其中...5.6 求$\Sigma_{1}^{20}n!=(1!+2!+3!+4!+...)$5.7 求$\Sigma_{k=1}^{100}k+...$5.13 用迭代法求$x=\sqrt(a)$... 第六单元6.1 用筛选法求100之内的素数6.2用选择法对10个整数排序6.3求一个3*3的整数矩阵对角线之和6.4 有一个已排好序的数组,要求输入一个数后,按原来排序规律插入数组中。6.5 将一个数组的值按逆时针排序...

第一单元 6,编写一个c程序,输入a,b,c三个值,输出其中最大者 #include int main() { int a, b, c,d; int max(int x, int y, int z); printf("enter three number:"); scanf_s("%d,%d,%d", &a, &b, &c); d = max(a, b, c); printf("max=%d\n", d); return 0; } int max(int x, int y, int z) { int max; max = x; if (max < y) max = y; if(maxc&&b==c 结果为0. 因为a+b=7>c=5,所以&&左边是真,用1表示。右边b==c用0表示。所以1&&0结果为0 (2)a||b+c&&b-c 结果为1。第93页的优先级别,算术运算符高于关系运算符,所以上面左边变成3||9为真,用1表示。右边为-1,故为1&&-1,都不是0,故为真,用1表示。 剩下几个一样的逻辑,自己分析。

4.4 3个整数,键盘输入,求最大值

此处采用两个方法, 1调用函数, 调用的是中的max函数,如果不写using namespace std则每个max都要改为std::max

#include #include #include using namespace std; int main() { int a, b, c,max_value; scanf_s("%d%d%d", &a, &b, &c); max_value = max(max(a, b), c); printf("%d", max_value); return 0; }

2 用条件表达式

#include #include #include using namespace std; int main() { int a, b, c,function(int,int,int); scanf_s("%d%d%d", &a, &b, &c); printf("%d", function(a,b,c)); return 0; } int function(int x, int y, int z) { int max_value = (x > y) ? x : y; return (max_value > z) ? max_value : z; } 4.5 从键盘输入一个小于1000的正数,要求输出它的平方根。。。。 #include #include #include using namespace std; int main() { int num, num1; printf("Please enter a positive number which is less than 1000: "); scanf_s("%d", &num); if (num >= 1000 || num 0) y = 1; else if (x == 0) y = 0; else y = -1; printf("%d", y); return 0; } 4.8 给出一百分制成绩,要求输出成绩等级。。。。

这里我使用了while,使得可以结束完一次之后进入下一次循环

#include #include #include using namespace std; int main() { float score; char grade; while (TRUE) { printf("Please enter your score: "); scanf_s("%f", &score); if (score > 100 || score < 0) { printf("Please check your input score,enter again: "); scanf_s("%f", &score); } switch (int (score/10)) { case 10: case 9:grade = 'A'; break; case 8:grade = 'B'; break; case 7:grade = 'C'; break; case 6:grade = 'D'; break; case 5: case 4: case 3: case 2: case 1: case 0:grade = 'E'; break; } printf("Your grade is %c\n", grade); } return 0; } 4.9 给一个不多于5位的正整数,要求:… #include #include #include using namespace std; int main() { int num,place,ten_thousand,thousand,hundred,ten,individual; printf("Please enter a positive number (0-99999):"); scanf_s("%d", &num); if (num > 9999) place = 5; else if (num > 999) place = 4; else if (num > 99) place = 3; else if (num > 9) place = 2; else place = 1; printf("Digit:%d", place); printf("Each number is: "); ten_thousand = num / 10000; thousand = (num - ten_thousand * 10000) / 1000; hundred = (num - ten_thousand * 10000 - thousand * 1000) / 100; ten = (num - ten_thousand * 10000 - thousand * 1000 - hundred * 100) / 10; individual = (num - ten_thousand * 10000 - thousand * 1000 - hundred * 100-ten*10); switch (place) { case 5:printf("%d,%d,%d,%d,%d\n", ten_thousand, thousand,hundred,ten,individual); printf("Inverse number:"); printf("%d,%d,%d,%d,%d\n", individual,ten,hundred,thousand,ten_thousand); } return 0; }

上面只给了五位数的例子,如10483,如果要加4,3,2,1位数,在switch下加case 4,case 3,即可。

4.10 企业发放的奖金。。。

这里我使用if编写,switch就不写了,比较简单。

#include #include #include using namespace std; int main() { float profit,bonus; printf("Please input profit:"); scanf_s("%f", &profit); if (profit < 100000) bonus = profit*0.1; else if (profit < 200000) bonus = 100000 * 0.1 + (profit - 100000)*0.075; else if (profit < 400000) bonus = 100000 * 0.1 + 100000 * 0.075 + (profit - 200000)*0.05; else if (profit


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3