c程序设计教程钱能课后答案

上传人:tang****xu2 文档编号:131977588 上传时间:2020-05-11 格式:DOCX 页数:9 大小:14.90KB
返回 下载 相关 举报
c程序设计教程钱能课后答案_第1页
第1页 / 共9页
c程序设计教程钱能课后答案_第2页
第2页 / 共9页
c程序设计教程钱能课后答案_第3页
第3页 / 共9页
c程序设计教程钱能课后答案_第4页
第4页 / 共9页
c程序设计教程钱能课后答案_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《c程序设计教程钱能课后答案》由会员分享,可在线阅读,更多相关《c程序设计教程钱能课后答案(9页珍藏版)》请在金锄头文库上搜索。

1、c 程序设计教程钱能课后答案篇一: c 语言程序设计教程 课后习题参考答案】t课后习题参考答案习题 11. ( 1)编译、链接 .exe( 2)函数 主函数(或 main 函数)( 3)编辑 编译 链接2.(1)-(5):ddbbc (6)-(10): abbbc3.( 1)答: c 语言简洁、紧凑,使用方便、灵活; c 语言是高级语言, 同时具备了低级语言的特征; c 语言是结构化程序设计语言,具有结 构化的程序控制语句; c 语言有各种各样的数据类型; c 语言可移植 性好;生成目标代码质量高,程序执行效率高。(2)编辑、编译、链接、执行(3)一个 c 程序由一或多个函数组成,一函数若干条

2、语句构成,每 条语句的末尾必须以分号结束。(4)标识符,关键字,运算符,分隔符,常量,注释符等4. 从键盘输入一个双精度小数,打印出它的余弦值。#include stdio.h#include math.hmain( )double x;scanf( “ %lf ”, x);printf(“ %nlf”, cos(x) );第2章1.(1)bde 、acfg(2)d (3) c (4) c2 (1)错( 2)错( 3)错( 4)对( 5)错3.( 1) a=3,b=-27(2) a=11,b=6,c=6(3) 3(4) 1 0 1 0 1 1 0(5) -9 9 8(6) 1)20 2)8 3

3、)70 4)0 5)0 6)0 4.(1)#include stdio.h main( ) double r, h ,v;r = 2.5; h = 3.5;v = 3.14*r*r*h; printf(“ v=%nlf” , v);(2) #include stdio.h main( ) char ch;ch = getchar( ); printf(“ %nc”, ch + 32);(3) #include stdio.h main( ) printf(“n*” );printf( “ *n*” ); printf( “ *n*” ); printf(“ *n*”);(4) #include

4、 stdio.h main( ) double x; scanf( “ %lf ”, x);printf( “ d , % Hi ” , (in t)x, x(in t);(5)#include stdio.h main( )double a=3, b=5;double result = (-2 * a + ( 4*a b )/( 2*a + b ) )/( (a - 4*b)/(a + b);printf(“ %nl”f , result);习题 31.(1) d(2)ad(3)c(4)b(5)a (6)-(10):bdacb2.(1) 3.141593,3.1416,3.142(2) c=

5、k(3) | 123.46|,|123 |(4) x=1.23,y= 50.00(5) 03.(1) scanf(%f ” , c)改为:seanf( “ f” , c);f = (9/5)*c+32; 改为: f = (9.0/5)*c + 32;printf( 摄“氏温度 %f 度相当于华氏温度 %f 度 ” , c, f); 改为: printf( 摄“氏温度 %f 度相当于华氏温度 %f 度” , c, f);(2)补充定义 :int h;h = 500/60 改为: h = 500 / 60;m = 500% 60 改为: m = 500%60;printf(“ 50分钟是 %d 小

6、时 %d 分钟,” h, m)改为:printf(“ 50分钟是%d小时%d分钟” ,h, m);4.(1 )#includestdio.hmain( )char x,y;scanf( “ %c%”c , x, y);printf(“ %nd” , (x-?0?) + (y-?0?) );(2)#include stdio.h main( )char x, y;char tmp;printf( “ input two characters:”);scanf( “ %c%”c , x, y);printf( “ before swap: x=%c, y=%c n”, x, y);tmp = x;

7、x = y;y = tmp; printf(“ after swap: x=%c, y=n%”c, x,y); (3)#include stdio.h main( )char ch;ch = getchar( );printf( “%nc”, ch - 32); 第4章1.(1)-(5): caaca2.(1)bbb(2) aaabbbccc(3) end(4) d=20(5) s=2,t=3(6) firstthird(7) y=0 y=5 y=10 y=53.(1)yz xz xy(2)ch=?a? ch=?z? ch=?a?ch=?z? ch = ch-32(2) x2x=10x-1x=

8、2(3) t=x; x=y; y=t;4.(1)#include stdio.hmain( )int x, y , z, t; scanf( “ %d%d%”d , x, y, z); if ( xy ) t=x; x=y; y=t; if( x z )【篇二:钱能 C+程序设计教程(第二版)第三章答案1】p /3.3.2 浮点数表示#inCludeiostreamusing namespaCe std;int main()/3.4.2 字符操作函数相关 #inCludeiostreamusing namespaCe std;int main() Char* s1=hello; Char* s

9、2=123; Char a20; strCpy(a,s1); Cout(strCmp(a,s1)=0?:not )equal.endl; CoutstrCat(a,s2)endl; Coutstrrev(a)endl; Coutstrset(a,C)endl;Cout(strstr(a,ell)?:not )find.endl; Cout(strChr(a,C)?:not )findendl; float f=19.2f; Coutfendl; unsigned int*p=reinterpret_Castunsigned int*(f); for(int i=31;i=0;i-) Cout(

10、*pi1)(i=31|i=23?-:); Coutendl;/3.4.3string 函数相关 #inCludeiostream #inCludestring using namespaCe std;int main()string a,s1=hello,s2=123; a=s1; Cout(a=s1?:not )equal.endl; Couta+s2endl; reverse(a.begin (),a.end(); Coutaendl; Couta.replaCe (0,9,9,C)endl;Cout(a.find(ell)?:not )findendl; Cout(a.find(C)?:

11、not )findendl; /3.4.5string 流 +文件流#inCludeiostream #inCludesstream#includefstreamusing namespace std;int main() ifstream fin(original.txt); for(string s;getline(fin,s);) int a,sum=0; for(istringstream sin(s);sina;sum+=a); coutsumendl;/3.5.2-sizeof() #includeiostream using namespace std; int main() i

12、nt a=1,15,8,3,8,48,2,64,5; for(int i=0;isizeof(a)/sizeof(a0);i+) cout ai; coutendl;/3.5.3- 初始化 #includeiostream using namespace std; int array15=1,2,3;int array25;int main()/3.5.4 二维数组 #includeiostream using namespace std;int main()int a23=1,2,3,4,5; int b23=1,2,4; coutarray1:endl; for(int i=0;isize

13、of(a)/sizeof(a0);i+) cout=endl; coutarray2:endl; for(int i=0;isizeof(b)/sizeof(b0);i+) cout ; for(int j=0;jsizeof(b0)/sizeof(b00);j+) cout ; for(int j=0;jsizeof(a0)/sizeof(a00);j+) coutaij ; coutendl; int array35=2; int array45; coutarray1:; for(int i=0;isizeof(array1)/sizeof(array10);i+) coutarray1

14、i ; coutendl; coutarray2:; for(int i=0;isizeof(array2)/sizeof(array20);i+) coutarray2i ; coutendl; coutarray3:; for(int i=0;isizeof(array3)/sizeof(array30);i+) coutarray3i ; coutendl; coutarray4:; for(inti=0;isizeof(array4)/sizeof(array40);i+) coutarray4i ; coutendl; coutbij ; coutendl; cout=endl;/3.6.2 文件流 + 向量#includeiostream #includefstream #includevector using namespace std;int main() ifstream fin(original.txt); vectorint va; for(int a;fina;) va.push_back(a); int s=0; for(vectorint:iterator p

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 其它中学文档

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