c语言程序设计实践教程答案(c语言程序设计实践教程答案解析薛纪文)
本篇文章给大家谈谈c语言程序设计实践教程答案,以及c语言程序设计实践教程答案解析薛纪文对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、求孙亚飞主编的C语言程序设计的课后答案啊啊
- 2、C语言程序设计教程(第二版) 周宇 课后答案
- 3、c语言程序设计教程答案
- 4、求c语言程序设计第三版和c语言程序设计实验与习题指导答案
- 5、C语言程序设计,求答案。万分感谢!
- 6、c语言程序设计教程 第四版 课后答案 (李丽娟).pdf
求孙亚飞主编的C语言程序设计的课后答案啊啊
百度有很多这个教程的答案,非常多。你自己根据需求去下《C语言程序设计实验指导与习题解答》是与孙力主编的《C语言程序设计》(中国农业出版社出版)配套使用的实验指导书。全书共有4章。第1章是C语言编译环境介绍,主要介绍了VisualC++6.0集成开发环境下编辑、编译、调试和运行程序的方法。第2章是上机实验内容,编写了配合《C语言程序设计》上机实验的47个实验和1个综合实训,实验内容循序渐进,由浅入深,分别由基础性实验、提高性实验、综合性和设计性实验构成。第3章是程序开发中的常见错误与调试。第4章是《C语言程序设计》每章末部分习题的参考答案。
C语言程序设计教程(第二版) 周宇 课后答案
二、 1. I love China! printf("we are students.\n") 2. 6 项目实训题参考答案 1.编写一个C程序,输出以下信息: * * * * * * * * * * * * * * * * * * * * I am a student! * * * * * * * * * * * * * * * * * * * * main() { printf("********************\n"); printf(" I am a student!\n "); printf("********************\n"); } 2222....已知立方体的长、宽、高分别是10cm、20cm、15cm,编写程序,求立方体体积。 解: main() { int a,b,c,v; a=10; b=20; c=15; v=a*b*c; printf("v=%d",v); } 本程序运行结果为: v=3000 第第第第2章章章章 编制编制编制编制C程序的基础知识程序的基础知识程序的基础知识程序的基础知识 一 选择题 C B A B A C C 二 操作题 2 21. 3,2,-8,2 3.000000,2.500000,-8.000000 2. ABC DE FGH why is 21+35 equal 52 3. 3 1 4 3 2 3 1 2 4. aa bb cc abc A N 项目实训题 1.定义一个符号常量M为5和一个变量n值为2,把它们的乘积输出。 #define M 5 main() { int n,c; n=2; c=M*n; printf("%d\n",c); } 2.编程求下面算术表达式的值。 (1)x+a%3*(int)(x+y)%2/4,设x=2.5,a=7,y=4.7; (2)(float)(a+b)/2+(int)x%(int)y,设a=2,b=3,x=3.5,y=2.5。 (1)main() { int a=7; float x=2.5,y=4.7; printf("%f\n",x+a%3*(int)(x+y)%2/4); } (2)main() { int a=2,b=3; float x=3.5,y=2.5; printf("%f\n",(float)(a+b)/2+(int)x%(int)y); 第三章第三章第三章第三章 顺序结构程序设计顺序结构程序设计顺序结构程序设计顺序结构程序设计 一 选择题 A C D C C 二 操作题 1. x=3,a=2,b=3 2. z=12.700000 3. 1 2 1 a 2 1 2 三三三三....编程题 编程题编程题编程题编程题 1. 某工种按小时计算工资,每月劳动时间(小时)×每小时工资=总工资,总工资中扣除10%公积金,剩余的为应发工资。编写一个程序从键盘输入劳动时间和每小时工资,打印出应发工资。 解: #include stdio.h main() { float sj,gz,yfgz; printf("time,salary:"); scanf("%f,%f",sj,gz); yfgz=sj*gz*0.9; printf("total salary:%f\n",yfgz); } 本程序运行结果为: time,salary:4,3CR total salary:10.800000 2.编写一个程序求出任意一个输入字符的ASCII码 解: #include stdio.h main() { char c; printf("Input a string:"); scanf("%c",c); printf("%c ASCII is %d\n",c,c); } 本程序运行结果为: Input a string:aCR a ASCII is 97 3、编写一个程序用于水果店售货员算帐:已知苹果每斤2.50元,鸭梨每斤1.80元,香蕉每斤2元,橘子每斤1.6元,要求输入各类水果的重量,打印出应付第四章第四章第四章第四章 选择结构程序设计选择结构程序设计选择结构程序设计选择结构程序设计 一、略 二、B B A B C B A 三、1. 1 0 2. 2 3 2 2 3. 10 20 0 4. ch=’A’ch=’Z’||ch=’a’ch=’z’ ch=’0’ch=’9’ ch==’ ’ 5. -1 四、上机操作 1. 从键盘输入一个英文字母,如果是大写字母,则将它变为小写字母输出;如果是小写字母,则将其变为大写字母输出。 #includestdio.h main() {char ch; ch=getchar(); if(ch='A'ch='Z') ch+=32; else if(ch='a'ch='z') ch-=32; putchar(ch); putchar('\n'); } 2. 根据输入的x值依据下列表达式,计算y的值。 2x (x-1) y = 3 (x=-1) 4+x (x-1) 解: main() { float x,y; scanf("%f",x); if(x-1) y=2*x; else if(x==1) y=3; else y=4+x; printf("y=%f",y); } 本程序运行结果为: -2CR y=2.000000 3.编写程序,输入一个整数,判断它是奇数还是偶数,若是奇数,输出“Is Odd“;若是偶数,输出“Is Even“。 main() { int x; scanf("%d",x); if(x%2==0) printf("Is Even\n"); else printf("Is Odd\n"); } 4.设计应用程序,求二次方程ax2+bx+c=0的解。 #includemath.h main() { float a,b,c,disc,x1,x2,p,q; scanf("%f,%f,%f",a,b,c); if(fabs(a)=1e-6) printf(" The equation is not a quadratic\n"); else { disc=b*b-4*a*c; if(fabs(disc) 1e-6) printf("x1=x2=%8.4f\n",-b/(2*a)); else if(disc1e-6) {x1=(-b+sqrt(disc)/(2*a)); x2=(-b-sqrt(disc)/(2*a)); printf("x1=%8.4f,x2=%8.4f\n",x1,x2); } else { p=-b/(2*a); q=sqrt(-disc/(2*a)); printf("%8.4f+%x8.4fi\n",p,q); printf("%8.4f-%8.4fi\n",p,q);} } } 5555....按托运规则,行李不超过50公斤时,运费为0.15元/公斤,如超过50公斤,超过部分的运费为0.22元/公斤,现有行李w公斤,编写一个程序计算运费。 解: #include stdio.h main() { float w,f,x; printf("weight:"); scanf("%f",w); if(w=50) x=0.15*w; else x=0.15*50+0.22*(w-50); printf("money:%6.2f yuan\n",x); } 本程序运行结果为: weight:20CR money:3.00 yuan weight:60CR money:9.70 yuan 6. 某商场给与顾客购物的折扣率如下: 购物金额200元 不打折 500元购物金额=200元 9折 1000元购物金额=500元 8折 购物金额=1000元 7.5折 输入一个购物金额,输出打折率、购物实际付款金额。 #includestdio.h main() { float x,y,realx; scanf("%f",x); if(x=0) { printf("Error! You input a worry number!\n"); y=0;} else { if(x200) y=1.0; else if(x500) y=0.9; else if(x1000) y=0.8; else y=0.75;} if(y!=0) {realx=x*y; printf("y=%f, the realx=%5.2f\n", y,realx);} } 第五章第五章第五章第五章 循环结构程序设计循环结构程序设计循环结构程序设计循环结构程序设计 一、选择题 C C A A D D第六章第六章第六章第六章 数组数组数组数组 、选择题 D A D A A C C A D 二、程序阅读题 13 13 13 13 13 13第七章第七章第七章第七章 函数函数函数函数 一、选择题 B D C B B D A A D第第第第8888章章章章 指针指针指针指针 一、选择题 D A C C(D) D C D 二、填空题 1. m 2. 指针数组名 3. ABCDCD 4.49 5. 25
c语言程序设计教程答案
#includestdio.
void main()
{
int x,y,z;
float ave;
printf("4,4,1:\n");
scanf("%d,%d,%d",x,y,z);
ave=(x+y+z)/3;
printf("3:ave=%f",ave);
}
求c语言程序设计第三版和c语言程序设计实验与习题指导答案
c语言程序设计第三版指导答案
附录F 课后题参考答案
习 题 1
1.1 填空题
1.函数
2.主函数main();主函数main() 3.主函数main() 4.函数首部;函数体 5.{;}
6.顺序结构;选择结构;循环结构 7..c;.obj;.exe
1.2 思考题
1.答:结构化程序设计是指,为使程序具有一个合理的结构以保证程序正确性而规定的一套如何进行程序设计的原则。顺序结构,选择结构,循环结构
2.答:算法是对具体问题求解步骤的一种描述。计算机算法的表达工具通常采用以下几种方法:①用自然语言表示算法;②用流程图表示算法;③用伪代码表示算法;④用程序设计语言表示算法。
3.略 4.略 5.略 1.3 编程题 1.答:
#include "stdio.h" main()
{ float a=10, b=20, h=5, s; s=(a+b)*h/2;
printf("s=%f " , s ); }
2.答:
#include "stdio.h"
main()
{ printf("******************************"); printf("* hello world *"); printf("******************************"); }
习 题 2
2.1 单选题
DBDCA DCABB CA
2.2 填空题
1.2.000000
2.1;0.500000
3.9;2 4.6 5.100;d 6.(1)20
(2)0
(3)60 7.(1)10;6;4
(2)6;9;15
(3)3;60;83
8.55或 '7'
9.x=4;y=6;z=3;m=463
2.3 改错题(略)
习 题 3
3.1 单选题
BDABC ADCAC BBA
3.2 填空题
1.3 2.261 3.10
4.2, 1;互换a,b的值 5.6.6 6.003 7.7
8.5.0,4,c=3Enter
9.i=10,j=20Enter
10. (1)65 (2)65,A (3)3.14,123.46
(4)3.141600e+000,1.234560e+002 (5)8765.432100 (6)8.765432e+003
11.a=2b=5x=8.8y=76.34c1=65c2=97 12.%d/%d;%d/%d=%.2f\n
3.3 改错题(略) 3.4 编程题
1.答:
#include "stdio.h" main() {
int x,y;
scanf("%d%d",x,y); printf("\t\tx\ty\n");
printf("十进制数\t%d\t%d\n",x,y); printf("八进制数\t%o\t%o\n",x,y); printf("十六进制数\t%X\t%x\n",x,y); }
2.答:
#include "stdio.h" main() {
char ch;
printf("请输入一个大写英文字母"); scanf("%c",ch);
printf("大写英文字母是%c\n",ch); printf("它的前导字符是%c\n",ch-1); printf("它的后续字符是%c\n",ch+1); }
3.答:
#include "stdio.h" main() {
int x,a,b,c,y;
printf("请输入一个三位整数\n"); scanf("%d",x); a=x/100;
b=(x-a*100)/10; c=x%10;
y=c*100+b*10+a;
printf("反向输出该整数:%d\n",y); } }
4.答:
#include "stdio.h" main()
{ int hour;
double salary, salaryday;
scanf("%d,%lf", hour, salaryday );
salary=hour*salaryday- hour*salaryday*0.1;
printf("%8.2lf\n", salary); }
5.答:
#include "stdio.h" main() {
int a,b,c,t;
printf("请输入三个整数\n"); scanf("%d%d%d",a,b,c);
printf("交换前a=%d,b=%d,c=%d\n",a,b,c); t=a;a=c;c=b;b=t;
printf("交换后a=%d,b=%d,c=%d\n",a,b,c); }
习 题 4
4.1 单选题
BADDD ACBBB BA
4.2 填空题
1.1
2.(1)a0 || b0
(2)x0 x=10 (3)a==1.5 b==1.5 c==1.5
(4)pa || pb || pc
3.(1)0 (2)1 (3)1 (4)0 (5)1
4.c=1 5.-4 6.1 7.5, 0, 3 8.5 9.123
10.( cvb= ='y'||cvb= ='Y')(work=3||college=='y'|| college=='Y')age=35
4.3 改错题(略) 4.4 编程题
1.答
#include "stdio.h"
#include "math.h" main() {
double a,b,c,p,area;
scanf("%lf%lf%lf",a,b,c);
printf("三角形的三边为:%.llf,%.1lf,%.1lf\n",a,b,c); if (a+bca+cbb+ca) {p=(a+b+c)/2;
area=sqrt(p*(p-a)*(p-b)*(p-c));
printf("三角形的面积为%.2lf\n",area); } else
printf("不能构成三角形\n"); }
2.答:
#include "stdio.h" main()
{ int x,y;
scanf("%d,%d",x,y); if(x*x+y*y1000)
printf("%d\n",(x*x+y*y)/100); else
printf("%d\n",x+y); }
3.答:
#include "stdio.h" #include "math.h" main()
{ double x,y;
scanf("%lf",x); if(x-2) y=x*x-sin(x); else if (x=2) y=pow(2,x)+x; else y=sqrt(x*x+x+1);
printf("x=%.2lf y=%.2lf\n",x,y); }
4.答:
#include "stdio.h" main( )
{ long ge,shi,qian,wan,x; scanf("%ld",x); wan=x/10000;
qian=x%10000/1000; shi=x%100/10;
ge=x%10;
if (ge==wanshi==qian) /*个位等于万位并且十位等于千位*/ printf("this number is a huiwen\n"); else
printf("this number is not a huiwen\n");
}
5.答:
#include "stdio.h" main()
{ float p,w,s,d,f;
scanf("%f,%,%f",p,s,w); if (s3000) d=0.15 else if( s=2000) d=0.1; else if(s=1000) d=0.08; else if(s=500) d=0.05; else if(s=250) d=0.02; else d=0 f=p*w*s*(1-d); printf("%f",f); }
6.答:
#include "stdio.h" main()
{ int year,money; char x;
printf("是否是本公司产品(y/n):"); scanf("%c",x);
if(x=='y'||x=='Y')
{printf("产品使用的年限:"); scanf("%d",year);
if(year=1) money=0;
else if(year8) money=50; else money=100;
printf("产品保修额是:%d\n",money);
}
else
{ money=200;
printf("不是本公司产品,产品保修额是:%d\n",money); } }
7.答:
#include "stdio.h" main()
{ int money,num1,num2;
printf("请输入取款额(≤2000):"); scanf("%d",money);
if(money2000) printf("请输入取款额数≤2000!\n"); else if(money%50==0) { num1=money/100; num2=(money-num1*100)/50; printf("需支付100元:%d张\n",num1); printf("需支付50元:%d张\n",num2); } else printf("输入钱数必须是50的倍数!\n"); }
习 题 5
5.1 单选题
CDABA ABDDB DBCB
5.2 填空题
1.2 0 2.333
3.(1)i10 或 i=9 (2)j%3!=0
4.(1)flag*(float)k/(k+1) 或1.0*flag*k/(k+1) (2)flag=-flag 5.(1)max=x
(2)x!=-1 (3)scanf("%d", x)
6.(1)x=9或x10
(2)y=9-x
5.3 改错题(略) 5.4 编程题
1.答:
(1)for循环,其他略
#include "stdio.h"
main()
{ int i,s=0;
for(i=1;i=100;i++) s+=i*i;
printf("%d\n",s); }
(2)for循环,其他略
#include "stdio.h" main()
{ int i=1,p=1; double s=1; do {
s+=1.0/p; p*=++i;
}while(1.0/p1e-6); printf("%lf",s); }
2.答:
#include "stdio.h" main()
{ int m,n,t,a,b;
scanf("%d,%d" ,m,n) if (mn)
{ t=m m=n n=t } a=m; b=n; t=m%n while(t)
{ m=n n=t t=m%n;} printf("%d",n); }
3.答:
#include "stdio.h" main()
{ int x,y,s=1;
scanf("%d,%d",x,y) for( y0 y--)s*=x
printf("%d,%d,%d\n ",s%10,s/10%10,s/100%10); }
4.答:
#include "stdio.h" main()
{ int x,y,z;
for( x=1 x20 x++) for( y=1 y33 y++) { z=100-x-y
if ((z%3)==0 (5*x+3*y+z/3)==100) printf("x=%d,y=%d,z=%d\n",x,y,z) } }
5.答: (a)
#include "stdio.h" main()
{ int j,k
for( j=1 j=4 j++)
{ for(k=1;k=4-j;k++)printf(" "); printf("****") printf("\n") } }
(b)
#include "stdio.h" main()
{ int j,k
for( j=1 j=4 j++)
{for(k=1;k=4-j;k++)printf(" "); for(k=1 k=2*j-1 k++) printf("*") printf("\n") } }
6.答:
程序分析:利用for循环控制在100~999之间,对每个数分解出个位、十位、百位。
#include stdio.h main() { int i,j,k,n; printf("water flower'number is:"); for(n=100;n1000;n++) { i=n/100;/*分解出百位*/ j=n/10%10;/*分解出十位*/ k=n%10;/*分解出个位*/ if(n==i*i*i+j*j*j+k*k*k) { printf("%-5d",n); } } printf("\n"); }
7.答:
#include stdio.h main() { int x; for(x=1000;x=3;x--) if(x%3==1x%5==2x%7==3) {
printf("该校的学生人数是:%d人\n",x); break; } }
8.答:
#include stdio.h main() { int x=12,i=1; while(1)
{ if((x+20+i)==2*(x+i)) break; i++; } printf("小明母亲在%d年后比小明的年龄大一倍\n",i); printf("那时小明年龄是:%d岁,小明母亲年龄是:%d岁\n",x+i,x+20+i); }
习 题 6
6.1 单选题
DBCCB BDC
C语言程序设计教程(第3版)
278
6.2 填空题
1.c 2.60 3.1000 10 4.16
6.3 编程题
1.答:
#include "stdio.h" #include "math.h"
#define F(a) a*a+ sqrt(3*a*a+2*a+1) main()
{ float x, f;
scanf("%f", x );
f=4.5/F(exp(x))+F(cos(x))+F(sqrt(x))/F(x*x) printf("%f\n", f); }
习 题 7
7.1 单选题
BCADA CCCDA BCBDB
7.2 填空题
1.(1)2 3 4 5 (2)10010 (3)QuickC
(4)10000 01000 00100 00010 00001 (5)Language
(6)Language Programming 2.(1)j+=2 (2)a[i]a[j] 3.(1)i=1 (2)x[i-1]
7.3 改错题(略) 7.4 编程题
1.答:
#define N 10
#include "stdio.h" main()
{ int a[N]={1,2,3,4,5,6,7,8,9,10,osum=0, qsum=0,j; for(j=0;j10;j++)
if( j%2) qsum+=a[j];
else osum+=a[j];
printf("osum=%d,qsum=%d\n", osum,qsum); }
2.答:
#define N 10
#include "stdio.h" main()
{ int a[N]={10,20,30,40,50,60,70,80,90}, j, k, x; scanf("%d",x); for(j=0;jN;j++)
if (xa[j]) break; if(j==N) a[N-1]=x; else
{for(k=N-1; kj; k--) a[k]=a[k-1]; a[j]=x;}
for(j=0;jN;j++)
printf("%d ",a[j]); }
3.答:
#define M 3
#include "stdio.h" main()
{ int a[M][M]={{1,2,3},{2,4,5},{3,5,6}},j,k,flag=1;; for( j=0;jM;j++)
for(k=0;kM;k++) if (a[j][k]!=a[k][j]) { flag=0; break;} if (flag) printf("ok"); else printf("NO"); }
4.答:
#include "stdio.h" #include "string.h" main()
{ char c1[10],c2[10],j; gets(c1); gets(c2);
for(j=0; (c1[j]==c2[j]) c1[j] c2[j]; j++); if (c1[j]c2[j]) printf("%d\n",1); if (c1[j]c2[j]) printf("%d\n",-1); if (c1[j]==c2[j]) printf("%d\n",0); }
5.答:
#include "stdio.h" #include "string.h" #define M 3 #define N 80 main()
{ char a[M][N],j,k,n[5]={0}; for(j=0;jM;j++) gets(a[j]);
for(j=0;jM;j++)
for(k=0;a[j][k];k++)
if( a[j][k]='A' a[j][k]='Z') n[0]++;
else if (a[j][k]='a' a[j][k]='z') n[1]++; else if (a[j][k]='0' a[j][k]='9') n[2]++; else if (a[j][k]==' ' ) n[3]++; else n[4]++;
for(j=0;j5;j++) printf("%4d", n[j]); }
习 题 8
8.1 单选题
DBDAC BACCC
8.2 填空题
1.(1)2, 1 (2)10#30# (3)FOUR, P (4)60
2.(1)49
(2)2
(3)2
(4)
(5)
8.3 改错题(略) 8.4 编程题
1.答:
#include "stdio.h"
main()
{ int n1,n2,n3,t; int *p1,*p2,*p3;
printf("please input 3 number:n1,n2,n3:"); scanf("%d,%d,%d",n1,n2,n3); p1=n1;
p2=n2; p3=n3;
if(*p1* p2) { t=*p1;*p1=*p2;*p2=t;}
if(*p1*p3) { t=*p1;*p1=*p3;*p3=t;} if(*p2*p3) { t=*p2;*p2=*p3;*p3=t;}
printf("the sorted numbers are:%d,%d,%d\n",n1,n2,n3); }
2.答:
#include "stdio.h" #define N 3 main()
{ int a[N],*p=a; for(;p-aN; p++) scanf("%d",p); p=a+N-1;
for(;p-a=0; p--) printf("%d ",*p); }
3.答:
#include "stdio.h" main()
{ int a[10];
int j,minl=0,maxl=0; for(j=0;j10;j++)
scanf("%d", a+j); for(j=0;j10;j++)
{ if(a[maxl]*(a+j)) maxl=j; if(a[minl]*(a+j)) minl=j; }
j=a[0]; a[0]=a[minl];a[minl]=j; j=a[9];a[9]=a[maxl];a[maxl]=j; for(j=0;j10;j++) printf("%d ", *(a+j)); }
4.答:
输入阵列如下: 1 2 3 4 5 6 7 8 9 10 11 12 输出阵列如下:
12 11 10 9 8 7 6 5 4 3 2 1
#define M 3
#define N 4
#include "stdio.h" main()
{ int a[M][N]={1,2,3,4,5,6,7,8,9,10,11,12},k,j,*p=a[0][0],t; for(k=0,j=M*N-1;kj;k++,j--)
{ t=*(p+k); *(p+k)=*(p+j); *(p+j)=t;} for (k=0 kM k++) { for(j=0 jN j++)
printf("%4d ",a[k][j]); printf("\n");
} }
5.答:
#include "stdio.h" main() {
int len;
char str[20],*p=str;
printf("please input a string:\n"); scanf("%s",str); len=0;
while(*p!='\0') {
len++; p++; }
printf("the string has %d characters.\n",len); }
6.答:
#include "string.h" #include "stdio.h" main() {
char *str1[5],ch[5][20],k,t,j,*c; void sort(char **); for(k=0;k5;k++) {str1[k]=ch[k]; gets(str1[k]);} for(k=0;k7;k++)
{ t=k;
for(j=k+1;j5;j++) if(strcmp(*(str1+t),*(str1+j))0) t=j; c=*(str1+t);
*(str1+t)=*(str1+k) *(str1+k)=c }
for(k=0;k5;k++) puts(str1[k]); }
习 题 9
9.1 单选题
CBBAD DBCCD DCABC BCCBA DCDAB
9.2 填空题
1.120 2.x 3.3,2,2,3 4.fac /i 5.8,17 6.9 7.1.0/(i*i) 8.
fun-in:30,20,10 fun-end:1015,35,1050 10,20,30 9.012345 10.93636 11.(1)r+b[k] (2)*x
12.7 5 3 1 9 13.15
14.(1)*x (2)t 15.(1)'\0' (2)n++ 16.024
9.3 改错题(略) 9.4 编程题
1.答:
void zhuan( )
{ char ch;
while((ch=getchar())!='\n')
{ if(ch='a' ch='z') ch=ch-32; putchar(ch); } }
2.答:
double expp(int n) { int k, fac=1; double sum=1;
for(k=1; k=n; k++) { fac*=k;
sum+=1.0/fac }
return(sum); }
3.答:
int xy3( int x, int y)
{ int k, num=1;
for(k=1;k=y k++) num*=x
num=num%1000 return num }
4.答:
int age( int n) { int c;
if(n==1) c=10
else c=age(n-1)+2 return c }
5.答:
#include "stdio.h"
main()
{ int a,b,c,d;
void fun(int a,int b,int *c, int *d); scanf("%d%d",a,b); fun(a,b,c,d);
printf("%d %d",c,d);
}
void fun(int a,int b,int *c, int *d) { if (b)
{ *c=a/b; *d=a%b;} }
6.答:
#include "stdio.h"
main(int argc,char *argv[]) { int k;
printf("argc=%d\n",argc); for (k=1;kargc; k++) printf("%s\n",argv[k]); }
习 题 10
10.1 单选题
CDBBB BBBAD CCBDC
10.2 填空题
1.所有结构体成员所占存储空间的总和 2.与占用存储空间最大的那个成员相等
附录F 课后题参考答案
285
3.(1)struct satype (2)3 (3)sa.a (4)9 (5)psa=sa 4.80 5.struct node 6.0
10.3 编程题
1.答:
#include "stdio.h"
struct student {
long num;
char name[20]; char sex; float score; }; main()
{ struct student s[20], temp; int j,k, man=0, woman=0;
float summan=0,sumwoman=0, aveman, avewoman; for(k=0; k20; k++)
{ scanf("%ld %s %c%f",s[k].num,s[k].name,s[k].sex,s[k].score); if(s[k].sex=='m')
{ summan+=s[k].score; man++;} else
{ sumwoman+=s[k].score;woman++ } }
aveman=summan/man;
avewoman=sumwoman/woman;
printf("%d\t%f\t%d\t%f\n",man,aveman,woman,avewoman); for(k=0; k19; k++)
for(j=0;j20-k;j++)
if(s[j].scores[j+1].score)
{ temp=s[j];s[j]=s[j+1];s[j+1]=temp;} printf("the sorted numbers:\n"); for(k=0;k20;k++)
printf("%ld\t%s\t%c\t%5.1f\n",s[k].num,s[k].name,s[k].sex,s[k].score); }
习 题 11
11.1 单选题
BADD
11.2 填空题
1.3d3d330 2.(1)28
(2)20 (3)0 (4)--9
3.(1)251
(2)42
(3)209
(4)–295 (5)848
习 题 12
12.1 单选题
BCDCA ADA
12.2 填空题
1.rewind(文件指针) 2."d1.dat","rb" 3.stdin
4.文本文件;二进制文件 5.(1)"w"
(2)str[i]--32
(3)"r"
6.fopen 7.Hello 8.(1)"r"
(2)fgetc(fp)
(3)time++
C语言程序设计实验与习题指导课后程序设计答案
P18
(1)
#includestdio.h int main(void) { intcelsius,fahr; fahr=150; celsius=5*fahr/9-5*32/9; printf("fahr=%d,celsius=%d\n",fahr,celsius); return 0; }
(2)
#includestdio.h int main(void) { intcelsius,fahr; celsius=26; fahr=9*celsius/5+32; printf("celsius=%d,fahr=%d\n",celsius,fahr); return 0; }
(3)
#includestdio.h int main(void) { intaverage,math,eng,comp; math=87; eng=72; comp=93; average=(math+eng+comp)/3; printf("math=%d,eng=%d,comp=%d,average=%d\n",math,eng,comp,average); return 0; }
(4)
#includestdio.h int main(void) { intn,a,b,c; n=152
c=n%10;
b=(n/10)%10; a=n/100;
printf("整数%d的个位数字是%d,十位数字是%d,百位数字是%d\n",n,c,b,a); return 0;
}
P27
(1)
#includestdio.h #includemath.h int main(void) { intcelsius,fahr; printf("Enter celsius:"); scanf("%d",celsius); fahr=9*celsius/5+32; printf("fahr%d\n",fahr); return 0; }
(2)
#includestdio.h #includemath.h int main(void) { intmoney,year; doublerate,interest; printf("Enter money,year,rate:"); scanf("%d%d%lf",money,year,rate); interest=money*pow(1+rate,year)-money; printf("interest=%.2f\n",interest); return 0; }
(3)
#includestdio.h #includemath.h int main(void) { doublex,y; printf("Enter x:"); scanf("%lf",x);
if(x0){ y=pow(x+1,2)+2*x+1/x; } else{ y=sqrt(x); }
printf("y=f(%f)=%.2f\n",x,y); return 0;
}
(4)
#includestdio.h int main(void) { intx,y; printf("Enter num1:"); scanf("%d",x); printf("Enter num2:"); scanf("%d",y); printf("%d+%d=%d\n",x,y,x+y); printf("%d-%d=%d\n",x,y,x-y); printf("%d*%d=%d\n",x,y,x*y); printf("%d/%d=%d\n",x,y,x/y); printf("%d%%%d=%d\n",x,y,x%y); return 0; }
10的阶乘
#includestdio.h int main(void) { inti,n,product; printf("Enter n:"); scanf("%d",n); product=1; for(i=1;i=n;i++){ product=product*i; } printf("product=%d\n",product); return 0; }
C语言程序设计,求答案。万分感谢!
第一题的:
#includestdio.h
int main()
{
char c;
scanf("%c",c);
if('a'=cc='z')
printf("%c\n",char(c-32));
else if('A'=cc='Z')
printf("%c\n",char(c+32));
else
printf("what you input is not a letter! ");
return 0;
}
第二题的:
#includestdio.h
int main()
{ int x,y;
printf("Please input your number x:\n");
scanf("%d",x);
if(x-1)
y=2*x;
else if(x-1)
y=4+x;
else y=3;
printf("%d",y);
return 0;
}
第三题:
#includestdio.h
int main()
{
int n;
printf("Please input a integer number:\n");
scanf("%d",n);
(n%2==0)?(printf("%d is Even\n",n)):(printf("%d is Odd\n",n));
return 0;
}
第四题的:
#includestdio.h
int main()
{
float x,y;
printf("请输入员工的业绩金额(万元):\n");
scanf("%f",x);
if(x1)
y=1.03*x;
else if(x=1x5)
y=1.1*x;
else if(x=5x20)
y=1.5*x;
else y=1.2*x;
printf("该员工的奖金数是%g万元\n",y);
return 0;
}
c语言程序设计教程 第四版 课后答案 (李丽娟).pdf
您要c语言程序设计教程
第四版
课答案
(李丽娟).pdf我已发送请按照步骤进行操作采纳我前进力记评采纳互相帮助c语言程序设计教程
第四版
课后答案
(李丽娟).pdf
c语言程序设计实践教程答案的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于c语言程序设计实践教程答案解析薛纪文、c语言程序设计实践教程答案的信息别忘了在本站进行查找喔。