爱收集资源网

循环实验答案,轻松掌握C语言程序设计

网络整理 2023-09-26 16:06

明天给诸位分享c语言程序设计指导实验答案的知识,其中也会对c++语言程序设计实验答案进行解释,倘若能偶然解决你如今面临的问题,别忘了关注本站,现今开始吧!

本文目录一览:C语言程序设计实验指导书答案魏海新

1、求1+2+3+……….+100。(循环)答案#includestdio.hvoidmain(){inti,sum=0;for(i=1;i=100;i++)sum=sum+i;printf("%d",sum);}2、求1*2*3*……….*10。(循环)答案voidmain(){inti=0,j=1;for(i=2;i=10;i++){j*=i;}printf("%d",j);return0;}3、输入三个数字,输出她们的最大值。(if)答案#includestdio.hvoidmain(){inta,b,c,d;scanf("%d,%d,%d",a,b,c);d=max(a,b,c);printf("max=%d",d);getch();/*暂停看运行结果*/}intmax(intx,inty,intz){intu;if(x=yx=z)u=x;elseif(y=xy=z)u=y;elseu=z;return(u);4.用起泡法对十个数据排序(链表实现)答案#includestdio.hmain(){inti,j,t;staticinta[10]={5,7,4,2,3,6,1,0,9,8};for(j=0;j9;j++){for(i=0;i9-j;i++){if(a[i]a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}for(i=0;i10;i++)printf("%2d",a[i]);}5、输入十个数字,倒序输出。

(链表实现)答案#includestdio.hmain(){inta[10],i=0;for(i=0;i=9;i++)scanf("%f",a[i]);printf("\n");for(i=9;i=0;i--)printf("%f",a[i]);}6输入两个数,交换她们的值并输出。(元素交换)答案#includestdio.hintmain(){intm,n,temp;scanf("%d%d",m,n);if(mn){temp=m;m=n;n=temp;}printf("%d",m);return0;}7.输出9*9加法表。(单层循环)答案#includestdio.hvoidmain(){inti=1;for(i;i=9;i++){intj=1;for(j;j=i;j++){printf("%d*%d=%d",i,j,i*j);}printf("\n");}}8.输入一行字符,将所有的大写字母转换成小写字母c语言程序设计实验指导与题解,小写字母转换成大写字母,其余字符不变。输出转变后的这行字符。

答案#include"stdio.h"voidmain(){chara[n];inti;scanf("%s",a);printf("小写为:");for(i=0;i=n;i++){if(a[i]='z'a[i]='a')a[i]=a[i]-32;printf("%c",a[i]);}printf("\n大写为:");for(i=0;i=3;i++){a[i]=a[i]+32;printf("%c",a[i]);}}9、编写一个简单估算器程序,要求才能完成两个数的+,-,*,/四种运算。输出运算式及运算结果。(switch)6.2#include"stdio.h"main(){charc;inti=0,j=0,k=0,l=0;while((c=getchar())!=’\n’){if(c=65c=90||c=97c=122)i++;elseif(c=48c=57)j++;elseif(c==32)k++;elsel++;}printf("i=%d,j=%d,k=%d,l=%d\n",i,j,k,l);}6.6#include"math.h"main(){intx=100,a,b,c;while(x=100x1000){a=0.01*x;b=10*(0.01*x-a);c=x-100*a-10*b;if(x==(pow(a,3)+pow(b,3)+pow(c,3)))printf("%5d",x);x++;}}6.7main(){intm,i,j,s;for(m=6;m10000;m++){s=1;for(i=2;im;i++)if(m%i==0)s=s+i;if(m-s==0){printf("%5ditsfastorsare1",m);for(j=2;jm;j++)if(m%j==0)printf("%d",j);printf("\n");}}}或main(){intm,i,j,s;for(m=6;m1000;m++){s=m-1;for(i=2;im;i++)if(m%i==0)s=s-i;if(s==0){printf("%5ditsfastorsare1",m);for(j=2;jm;j++)if(m%j==0)printf("%d",j);printf("\n");}}}6.8main(){inti=1,n;doublet,x=1,y=2,s,sum=0;scanf("%ld",n);while(i=n){s=y/x;sum=sum+s;t=y;y=y+x;x=t;i++;}printf("%f\n",sum);}11,P128例6.10(解调)#includestdio.hvoidmain(){charc;while((c=getchar())!='\n'){c=c+4;if(c'Z'+4||c'z')c=c-26;}printf("%c",c);}printf("\n");}12,P1115.55.6(switch)5.5#includestdio.hmain(){intx,y;printf("输入x:");scanf("%d",x);if(x1){y=x;printf("x=%3d,y=x=%d\n",x,y);}elseif(x10){y=2*x-1;printf("x=%3d,y=2*x-1=%d\n",x,y);}else{y=3*x-11;printf("x=%3d,y=3*x-11=%d\n",x,y);}}5.6#includestdio.hmain(){floatscore;chargrade;case2:printf("请输入中学生成绩:");scanf("%f",score);while(score100||(score0){printf("\n输入有误,请重新输入:");scanf("%f",score);}switch((int)(score/10)){case10:case9:grade=’A’;break;case8:grade=’B’;break;case7:grade=’C’;break;case6:grade=’D’;break;case5:case4:case3:case1:case0:grade=’E’;}printf("成绩是%5.1f,相应的等级是%c。

\n",score,grade);}13,P108例5.5(一元二次方程求根)例5.6(求闰月)5.5#includestdio.hvoidmain(){intyear,leap;scanf("%d",year);if(year%4==0){if(year0==0){if(year%400==0)leap=1;elseleap=0;}elseleap=1;}elseleap=0;if(leap)printf("%dis",year);elseprintf("%disnot",year);printf("aleapyear.\n")}5.614,P31例2.17例2.182.17输出50个中学生中成绩低于80分者的学号和成绩2.18输出2000——2500年每一年是否闰月#includestdio.hvoidmain(){intyear;year=2000;go:if(((year%4==0)(year0!=0))||(year%400==0))printf("%disrunzi",year);if(year=2500)year=year++;if(year2500)gotoend;gotogo;end:getch();}希望对你有所帮助

c语言程序设计实验与习题指导颜晖主编第三版答案,有的私信我

1、求1+2+3+……….+100。(循环)答案#includevoidmain(){inti,sum=0;for(i=1;ivoidmain(){inta,b,c,d;scanf("%d,%d,%d",a,b,c);d=max(a,b,c);printf("max=%d",d);getch();/*暂停看运行结果*/}intmax(intx,inty,intz){intu;if(x=yx=z)u=x;elseif(y=xy=z)u=y;elseu=z;return(u);4.用起泡法对十个数据排序(链表实现)答案#includemain(){inti,j,t;staticinta[10]={5,7,4,2,3,6,1,0,9,8};for(j=0;ja[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}for(i=0;imain(){inta[10],i=0;for(i=0;i=0;i--)printf("%f",a[i]);}6输入两个数,交换她们的值并输出。(元素交换)答案#includeintmain(){intm,n,temp;scanf("%d%d",m,n);if(mvoidmain(){inti=1;for(i;i='a')a[i]=a[i]-32;printf("%c",a[i]);}printf("\n大写为:");for(i=0;i=65c=97c=48c=100xvoidmain(){charc;while((c=getchar())!='\n'){c=c+4;if(c'Z'+4||c'z')c=c-26;}printf("%c",c);}printf("\n");}12,P1115.55.6(switch)5.5#includemain(){intx,y;printf("输入x:");scanf("%d",x);if(xmain(){floatscore;chargrade;case2:printf("请输入中学生成绩:");scanf("%f",score);while(score100||(scorevoidmain(){intyear,leap;scanf("%d",year);if(year%4==0){if(year0==0){if(year%400==0)leap=1;elseleap=0;}elseleap=1;}elseleap=0;if(leap)printf("%dis",year);elseprintf("%disnot",year);printf("aleapyear.\n")}5.614,P31例2.17例2.182.17输出50个中学生中成绩低于80分者的学号和成绩2.18输出2000——2500年每一年是否闰月#includevoidmain(){intyear;year=2000;go:if(((year%4==0)(year0!=0))||(year%400==0))printf("%disrunnian",year);if(year2500)gotoend;gotogo;end:getch();}希望对你有所帮助

求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()

{floata=10,b=20,h=5,s;s=(a+b)*h/2;

printf("s=%f",s);}

2.答:

#include"stdio.h"

main()

{printf("******************************");printf("*helloworld*");printf("******************************");}

习题2

2.1单选题

DBDCADCABBCA

2.2填空题

1.2.000000

2.1;0.500000

3.9;24.65.100;d6.(1)20

(2)0

(3)607.(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单选题

BDABCADCACBBA

3.2填空题

1.32.2613.10

4.2,1;互换a,b的值5.6.66.0037.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=9712.%d/%d;%d/%d=%.2f\n

3.3改错题(略)3.4编程题

1.答:

#include"stdio.h"main(){

intx,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(){

charch;

printf("请输入一个小写英语字母");scanf("%c",ch);

printf("小写英语字母是%c\n",ch);printf("它的前导字符是%c\n",ch-1);printf("它的后续字符是%c\n",ch+1);}

3.答:

#include"stdio.h"main(){

intx,a,b,c,y;

printf("请输入一个三位整数\n");scanf("%d",x);a=x/100;

b=(x-a*100)/10;c=x;

y=c*100+b*10+a;

printf("反向输出该整数:%d\n",y);}}

4.答:

#include"stdio.h"main()

{inthour;

doublesalary,salaryday;

scanf("%d,%lf",hour,salaryday);

salary=hour*salaryday-hour*salaryday*0.1;

printf("%8.2lf\n",salary);}

5.答:

#include"stdio.h"main(){

inta,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单选题

BADDDACBBBBA

4.2填空题

1.1

2.(1)a0||b0

(2)x0x=10(3)a==1.5b==1.5c==1.5

(4)pa||pb||pc

3.(1)0(2)1(3)1(4)0(5)1

4.c=15.-46.17.5,0,38.59.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(){

doublea,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()

{intx,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()

{doublex,y;

scanf("%lf",x);if(x-2)y=x*x-sin(x);elseif(x=2)y=pow(2,x)+x;elsey=sqrt(x*x+x+1);

printf("x=%.2lfy=%.2lf\n",x,y);}

4.答:

#include"stdio.h"main()

{longge,shi,qian,wan,x;scanf("%ld",x);wan=x/10000;

qian=x000/1000;shi=x0/10;

ge=x;

if(ge==wanshi==qian)/*个位等于万位而且十位等于千位*/printf("thisnumberisahuiwen\n");else

printf("thisnumberisnotahuiwen\n");

5.答:

#include"stdio.h"main()

{floatp,w,s,d,f;

scanf("%f,%,%f",p,s,w);if(s3000)d=0.15elseif(s=2000)d=0.1;elseif(s=1000)d=0.08;elseif(s=500)d=0.05;elseif(s=250)d=0.02;elsed=0f=p*w*s*(1-d);printf("%f",f);}

6.答:

#include"stdio.h"main()

{intyear,money;charx;

printf("是否是本公司产品(y/n):");scanf("%c",x);

if(x=='y'||x=='Y')

{printf("产品使用的期限:");scanf("%d",year);

if(year=1)money=0;

elseif(year8)money=50;elsemoney=100;

printf("产品质保额是:%d\n",money);

else

{money=200;

printf("不是本公司产品,产品质保额是:%d\n",money);}}

7.答:

#include"stdio.h"main()

{intmoney,num1,num2;

printf("请输入提款额(≤2000):");scanf("%d",money);

if(money2000)printf("请输入提款额数≤2000!\n");elseif(money%50==0){num1=money/100;num2=(money-num1*100)/50;printf("需支付100元:%d张\n",num1);printf("需支付50元:%d张\n",num2);}elseprintf("输入钱数必须是50的倍数!\n");}

习题5

5.1单选题

CDABAABDDBDBCB

5.2填空题

1.202.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=-flag5.(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()

{inti,s=0;

for(i=1;i=100;i++)s+=i*i;

printf("%d\n",s);}

(2)for循环,其他略

#include"stdio.h"main()

{inti=1,p=1;doubles=1;do{

s+=1.0/p;p*=++i;

}while(1.0/p1e-6);printf("%lf",s);}

2.答:

#include"stdio.h"main()

{intm,n,t,a,b;

scanf("%d,%d",m,n)if(mn)

{t=mm=nn=t}a=m;b=n;t=m%nwhile(t)

{m=nn=tt=m%n;}printf("%d",n);}

3.答:

#include"stdio.h"main()

{intx,y,s=1;

scanf("%d,%d",x,y)for(y0y--)s*=x

printf("%d,%d,%d\n",s,s/10,s/100);}

4.答:

#include"stdio.h"main()

{intx,y,z;

for(x=1x20x++)for(y=1y33y++){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()

{intj,k

for(j=1j=4j++)

{for(k=1;k=4-j;k++)printf("");printf("****")printf("\n")}}

(b)

#include"stdio.h"main()

{intj,k

for(j=1j=4j++)

{for(k=1;k=4-j;k++)printf("");for(k=1k=2*j-1k++)printf("*")printf("\n")}}

6.答:

程序剖析:借助for循环控制在100~999之间,对每位数分解出个位、十位、百位。

#includestdio.hmain(){inti,j,k,n;printf("waterflower'numberis:");for(n=100;n1000;n++){i=n/100;/*分解出百位*/j=n/10;/*分解出十位*/k=n;/*分解出个位*/if(n==i*i*i+j*j*j+k*k*k){printf("%-5d",n);}}printf("\n");}

7.答:

#includestdio.hmain(){intx;for(x=1000;x=3;x--)if(x%3==1x%5==2x%7==3){

printf("该校的中学生人数是:%d人\n",x);break;}}

8.答:

#includestdio.hmain(){intx=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单选题

DBCCBBDC

C语言程序设计教程(第3版)

278

6.2填空题

1.c2.603.1000104.16

6.3编程题

1.答:

#include"stdio.h"#include"math.h"

#defineF(a)a*a+sqrt(3*a*a+2*a+1)main()

{floatx,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单选题

BCADACCCDABCBDB

7.2填空题

1.(1)2345(2)10010(3)QuickC

(4)1000001000001000001000001(5)Language

(6)LanguageProgramming2.(1)j+=2(2)a[i]a[j]3.(1)i=1(2)x[i-1]

7.3改错题(略)7.4编程题

1.答:

#defineN10

#include"stdio.h"main()

{inta[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];

elseosum+=a[j];

printf("osum=%d,qsum=%d\n",osum,qsum);}

2.答:

#defineN10

#include"stdio.h"main()

{inta[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.答:

#defineM3

#include"stdio.h"main()

{inta[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");elseprintf("NO");}

4.答:

#include"stdio.h"#include"string.h"main()

{charc1[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"#defineM3#defineN80main()

{chara[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]++;

elseif(a[j][k]='a'a[j][k]='z')n[1]++;elseif(a[j][k]='0'a[j][k]='9')n[2]++;elseif(a[j][k]=='')n[3]++;elsen[4]++;

for(j=0;j5;j++)printf("%4d",n[j]);}

习题8

8.1单选题

DBDACBACCC

8.2填空题

1.(1)2,1(2)10#30#(3)FOUR,P(4)60

2.(1)49

(2)2

c语言程序设计实验指导与题解_解题实验指导程序语言设计方法_程序设计实验指导与测试

(3)2

(4)

(5)

8.3改错题(略)8.4编程题

1.答:

#include"stdio.h"

main()

{intn1,n2,n3,t;int*p1,*p2,*p3;

printf("pleaseinput3number: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("thesortednumbersare:%d,%d,%d\n",n1,n2,n3);}

2.答:

#include"stdio.h"#defineN3main()

{inta[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()

{inta[10];

intj,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.答:

输入阵列如下:123456789101112输出阵列如下:

121110987654321

#defineM3

#defineN4

#include"stdio.h"main()

{inta[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=0kMk++){for(j=0jNj++)

printf("%4d",a[k][j]);printf("\n");

}}

5.答:

#include"stdio.h"main(){

intlen;

charstr[20],*p=str;

printf("pleaseinputastring:\n");scanf("%s",str);len=0;

while(*p!='\0'){

len++;p++;}

printf("thestringhas%dcharacters.\n",len);}

6.答:

#include"string.h"#include"stdio.h"main(){

char*str1[5],ch[5][20],k,t,j,*c;voidsort(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单选题

CBBADDBCCDDCABCBCCBADCDAB

9.2填空题

1.1202.x3.3,2,2,34.fac/i5.8,176.97.1.0/(i*i)8.

fun-in:30,20,10fun-end:1015,35,105010,20,309.01234510.9363611.(1)r+b[k](2)*x

12.7531913.15

14.(1)*x(2)t15.(1)'\0'(2)n++16.024

9.3改错题(略)9.4编程题

1.答:

voidzhuan()

{charch;

while((ch=getchar())!='\n')

{if(ch='a'ch='z')ch=ch-32;putchar(ch);}}

2.答:

doubleexpp(intn){intk,fac=1;doublesum=1;

for(k=1;k=n;k++){fac*=k;

sum+=1.0/fac}

return(sum);}

3.答:

intxy3(intx,inty)

{intk,num=1;

for(k=1;k=yk++)num*=x

num=num00returnnum}

4.答:

intage(intn){intc;

if(n==1)c=10

elsec=age(n-1)+2returnc}

5.答:

#include"stdio.h"

main()

{inta,b,c,d;

voidfun(inta,intb,int*c,int*d);scanf("%d%d",a,b);fun(a,b,c,d);

printf("%d%d",c,d);

voidfun(inta,intb,int*c,int*d){if(b)

{*c=a/b;*d=a%b;}}

6.答:

#include"stdio.h"

main(intargc,char*argv[]){intk;

printf("argc=%d\n",argc);for(k=1;kargc;k++)printf("%s\n",argv[k]);}

习题10

10.1单选题

CDBBBBBBADCCBDC

10.2填空题

1.所有结构体成员所占储存空间的总和2.与占用储存空间最大的那种成员相等

附表F课后题参考答案

285

3.(1)structsatype(2)3(3)sa.a(4)9(5)psa=sa4.805.structnode6.0

10.3编程题

1.答:

#include"stdio.h"

structstudent{

longnum;

charname[20];charsex;floatscore;};main()

{structstudents[20],temp;intj,k,man=0,woman=0;

floatsumman=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("thesortednumbers:\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.3d3d3302.(1)28

(2)20(3)0(4)--9

3.(1)251

(2)42

(3)209

(4)–295(5)848

习题12

12.1单选题

BCDCAADA

12.2填空题

1.rewind(文件表针)2."d1.dat","rb"3.stdin

4.文本文件;二补码文件5.(1)"w"

(2)str[i]--32

(3)"r"

6.fopen7.Hello8.(1)"r"

(2)fgetc(fp)

(3)time++

C语言程序设计实验与习题指导课后程序设计答案

P18

(1)

#includestdio.hintmain(void){intcelsius,fahr;fahr=150;celsius=5*fahr/9-5*32/9;printf("fahr=%d,celsius=%d\n",fahr,celsius);return0;}

(2)

#includestdio.hintmain(void){intcelsius,fahr;celsius=26;fahr=9*celsius/5+32;printf("celsius=%d,fahr=%d\n",celsius,fahr);return0;}

(3)

#includestdio.hintmain(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);return0;}

(4)

#includestdio.hintmain(void){intn,a,b,c;n=152

c=n;

b=(n/10);a=n/100;

printf("整数%d的个位数字是%d,十位数字是%d,百位数字是%d\n",n,c,b,a);return0;

P27

(1)

#includestdio.h#includemath.hintmain(void){intcelsius,fahr;printf("Entercelsius:");scanf("%d",celsius);fahr=9*celsius/5+32;printf("fahr%d\n",fahr);return0;}

(2)

#includestdio.h#includemath.hintmain(void){intmoney,year;doublerate,interest;printf("Entermoney,year,rate:");scanf("%d%d%lf",money,year,rate);interest=money*pow(1+rate,year)-money;printf("interest=%.2f\n",interest);return0;}

(3)

#includestdio.h#includemath.hintmain(void){doublex,y;printf("Enterx:");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);return0;

(4)

#includestdio.hintmain(void){intx,y;printf("Enternum1:");scanf("%d",x);printf("Enternum2:");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);return0;}

10的阶乘

#includestdio.hintmain(void){inti,n,product;printf("Entern:");scanf("%d",n);product=1;for(i=1;i=n;i++){product=product*i;}printf("product=%d\n",product);return0;}

求c语言程序设计第二版(苏小红)课后第五章的本章实验题答案

《0300C语言全59讲主讲-苏小红西安工业学院》百度云盘资源免费下载

?pwd=riuy提取码:riuy

0300C语言全59讲主讲-苏小红西安工业学院|各学科学习视频目录|1-30讲|课程目录.txt|C语言哈师大教材苏小红.jpg|9.flv|8.flv|7.flv|6.flv|5.flv|4.flv|30.flv|3.flv|29.flv|28.flv

跪求===《C语言程序设计实验·设计·习题》的答案

这是谭浩强版习题题答案,看与你的是否一致

1.5请参照本章例题,编撰一个C程序,输出以下信息:

************

VeryGoodj!

************

解:

main()

printf("************\n");

printf("\n");

printf("VeryGood!\n");

printf("\n");

printf("************\n");

1.6编撰一个程序,输入abc三个值,输出其中最大者。

解:main()

{inta,b,c,max;

printf("请输入三个数a,b,c:\n");

scanf("%d,%d,%d",a,b,c);

max=a;

if(maxB)

max=b;

if(maxC)

max=c;

printf("最大数为:%d",max);

第三章

3.3请将下边各数用八补码数和十六补码数表示:

(1)10(2)32(3)75(4)-617

(5)-111(6)2483(7)-28654(8)21003

解:十八十六

(10)=(12)=(a)

(32)=(40)=20

(75)=(113)=4b

(-617)=(176627)=fd97

-111=177621=ff91

2483=4663=963

-28654=110022=9012

21003=51013=520b

3.5字符常量与字符串常量有哪些区别?

解:字符常量是一个字符,用单冒号括上去。字符串常量是由0个或若干个字符

而成,用双冒号把它们括上去,储存时手动在字符串最后加一个结束符号'\0'.

3.6写出以下程序的运行结果:

#include

voidmain()

charc1='a',c2='b',c3='c',c4='\101',c5='\116';

printf("a%cb%c\tc%c\tabc\n",c1,c2,c3);

printf("\t\b%c%c\n",c4,c5);

解:程序的运行结果为:

aabbccabc

AN

3.7将"China"译成密码.密码规律:用原先的字母前面第4个字母替代原先的字母,

比如,字母"A"前面第4个字母是"E",用"E"取代"A".因而,"China"应译为"Glmre".

请编一程序,用赋终值的议题使c1,c2,c3,c4,c5分别弄成'G','1','m','r','e',并

输出.

main()

{charc1="C",c2="h",c3="i",c4='n',c5='a';

c1+=4;

c2+=4;

c3+=4;

c4+=4;

c5+=4;

printf("密码是%c%c%c%c%c\n",c1,c2,c3,c4,c5);

3.8例3.6能够改成如下:

#include

voidmain()

intc1,c2;(原为charc1,c2)

c1=97;

c2=98;

printf("%c%c\n",c1,c2);

printf("%d%d\n",c1,c2);

解:可以.由于在可输出的字符范围内,用整型和字符型作用相同.

3.9求下边算术表达式的值.

(1)x+a%3*(int)(x+y)%2/4=2.5(x=2.5,a=7,y=4.7)

(2)(float)(a+b)/2+(int)x%(int)y=3.5(设a=2,b=3,x=3.5,y=2.5)

3.10写出下边程序的运行结果:

#include

voidmain()

inti,j,m,n;

i=8;

j=10;

m=++i;

n=j++;

printf("%d,%d,%d,%d\n",i,j,m,n);

解:结果:9,11,9,10

第4章

4.4.a=3,b=4,c=5,x=1.2,y=2.4,z=-3.6,u=51274,n=128765,c1='a',c2='b'.想得

到以下的输出格式和结果,请写出程序要求输出的结果如下:

a=3b=4c=5

x=1.200000,y=2.400000,z=-3.600000

x+y=3.60y+z=-1.20z+x=-2.40

u=51274n=128765

c1='a'or97(ASCII)

c2='B'or98(ASCII)

解:

main()

c语言程序设计实验指导与题解_程序设计实验指导与测试_解题实验指导程序语言设计方法

inta,b,c;

longintu,n;

floatx,y,z;

charc1,c2;

a=3;b=4;c=5;

x=1.2;y=2.4;z=-3.6;

u=51274;n=128765;

c1='a';c2='b';

printf("\n");

printf("a=%2db=%2dc=%2d\n",a,b,c);

printf("x=%8.6f,y=%8.6f,z=%9.6f\n",x,y,z);

printf("x+y=%5.2fy=z=%5.2fz+x=%5.2f\n",x+y,y+z,z+x);

printf("u=%6ldn=%9ld\n",u,n);

printf("c1='%c'or%d(ASCII)\n",c1,c2);

printf("c2='%c'or%d(ASCII)\n",c2,c2);

4.5请写出下边程序的输出结果.

结果:

57

57

67.856400,-789.123962

67.856400,-789.123962

67.86,-789.12,67.856400,-789.123962,67.856400,-789.123962

6.785640e+001,-7.89e+002

A,65,101,41

1234567,4553207,d687

65535,17777,ffff,-1

COMPUTER,COM

4.6用下边的scanf函数输入数据,使a=3,b=7,x=8.5,y=71.82,c1='A',c2='a',

问在鼠标上怎么输入?

main()

inta,b;

floatx,y;

charc1,c2;

scanf("a=%db=%d,a,b);

scanf("x=%fy=%e",x,y);

scanf("c1=%cc2=%c",c1,c2);

解:可按如下方法在按键上输入:

a=3b=7

x=8.5y=71.82

c1=Ac2=a

说明:在边疆使用一个或多个scnaf函数时,第一个输入行末尾输入的"回车"被第二

个scanf函数吸收,因而在第二\三个scanf函数的双冒号后设一个空格以抵消上行

入的"回车".若果没有这个空格,按里面输入数据会出错,读者目前对此只留有一

初步概念即可,之后再进一步深入理解.

4.7用下边的scanf函数输入数据使a=10,b=20,c1='A',c2='a',x=1.5,y=-

3.75,z=57.8,请问

在按键上怎么输入数据?

scanf("%5d%5d%c%c%f%f%*f%f",a,b,c1,c2,y,z);

解:

main()

inta,b;

floatx,y,z;

charc1,c2;

scanf("%5d%5d%c%c%f%f",a,b,c1,c2,x,y,z);

运行时输入:

1020Aa1.5-3.75+1.5,67.8

注解:按%5d格式的要求输入a与b时c语言程序设计实验指导与题解,要先键入三个空格,而后再攻入10与20。%*f

是拿来严禁形参的。在输入时,对应于%*f的地方,随便攻入了一个数1.5,该值不

会赋给任何变量。

4.8设圆直径r=1.5,圆锥高h=3,求圆周长,圆面积,球体表面积,球体容积,圆锥容积,

用scanf输入数据,输出估算结果,输出时要求有文字说明,取小数点后两位数字.请编

程.

解:main()

floatpi,h,r,l,s,sq,vq,vz;

pi=3.1415926;

printf("请输入圆直径r圆锥高h:\n");

scanf("%f,%f",r,h);

l=2*pi*r;

s=r*r*pi;

sq=4*pi*r*r;

vq=4.0/3.0*pi*r*r*r;

vz=pi*r*r*h;

printf("圆周长为:=%6.2f\n",l);

printf("圆面积为:=%6.2f\n",s);

printf("球体表面积为:=%6.2f\n",sq);

printf("球体容积为:=%6.2f\n",vz);

4.9输入一个华氏湿度,要求输出摄氏湿度,公式为C=5/9(F-32),输出要有文字说明,

取两位小数.

解:main()

floatc,f;

printf("请输入一个华氏气温:\n");

scanf("%f",f);

c=(5.0/9.0)*(f-32);

printf("摄氏气温为:%5.2f\n",c);

第五章逻辑运算和判定选定结构

5.4有三个整数a,b,c,由鼠标输入,输出其中最大的数.

main()

inta,b,c;

printf("请输入三个数:");

scanf("%d,%d,%d",a,b,c);

if(aB)

if(bC)

printf("max=%d\n",c);

else

printf("max=%d\n",b);

elseif(aC)

printf("max=%d\n",c);

else

printf("max-%d\n",a);

方式2:使用条件表达式.

main()

{inta,b,c,termp,max;

printf("请输入A,B,C:");

scanf("%d,%d,%d",a,b,c);

printf("A=%d,B=%d,C=%d\n",a,b,c);

temp=(ab)?a:b;

max=(tempc)?temp:c;

printf("A,B,C中最大数是%d,",max);

5.5main()

{intx,y;

printf("输入x:");

scanf("%d",x);

if(x1)

{y=x;

printf("X-%d,Y=X=%d\n",x,y);

elseif(x10)

{y=2*x-1;

printf("X=%d,Y=2*X-1=%d\n",x,y);

else

{y=3*x-11;

printf("X=5d,Y=3*x-11=%d\n",x,y);

(习题5-6:)自己写的早已运行成功!不同的人有不同的算法,这种答案仅供参考!818pp.com

#include

voidmain()

floats,i;

chara;

scanf("%f",s);

while(s100||s0)

printf("输入错误!error!");

scanf("%f",s);

i=s/10;

switch((int)i)

case10:

case9:a='A';break;

case8:a='B';break;

case7:a='C';break;

case6:a='D';break;

case5:

case4:

case2:

case1:

case0:a='E';

printf("%c",a);

5.7给一个不少于5位的正整数,要求:1.求它是几位数2.分别复印出每一位数字3.

按降序复印出诸位数字.比如原数为321,应输出123.

main()

longintnum;

intindiv,ten,hundred,housand,tenthousand,place;

printf("请输入一个整数(0-99999):");

scanf("%ld",num);

if(num9999)

place=5;

elseif(num999)

place=4;

elseif(num99)

place=3;

elseif(num9)

place=2;

elseplace=1;

printf("place=%d\n",place);

printf("每位数字为:");

ten_thousand=num/10000;

thousand=(num-tenthousand*10000)/1000;

hundred=(num-tenthousand*10000-thousand*1000)/100;

ten=(num-tenthousand*10000-thousand*1000-hundred*100)/10;

indiv=num-tenthousand*10000-thousand*1000-hundred*100-ten*10;

switch(place)

{case5:printf("%d,%d,%d,%d,%d",tenthousand,thousand,hundred,ten,indiv);

printf("\n反序数字为:");

printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,tenthousand);

break;

case4:printf("%d,%d,%d,%d",thousand,hundred,ten,indiv);

printf("\n反序数字为:");

printf("%d%d%d%d\n",indiv,ten,hundred,thousand);

break;

case3:printf("%d,%d,%d\n",hundred,ten,indiv);

printf("\n反序数字为:");

printf("%d%d%d\n",indiv,ten,hundred);

case2:printf("%d,%d\n",ten,indiv);

printf("\n反序数字为:");

printf("%d%d\n",indiv,ten);

case1:printf("%d\n",indiv);

printf("\n反序数字为:");

printf("%d\n",indiv);

5.8

1.if句子

main()

{longi;

floatbonus,bon1,bon2,bon4,bon6,bon10;

bon1=100000*0.1;

bon2=bon1+100000*0.075;

bon4=bon2+200000*0.05;

bon6=bon4+200000*0.03;

bon10=bon6+400000*0.015;

scanf("%ld",i);

if(i=1e5)bonus=i*0.1;

elseif(i=2e5)bonus=bon1+(i-100000)*0.075;

elseif(i=4e5)bonus=bon2+(i-200000)*0.05;

elseif(i=6e5)bonus=bon4+(i-400000)*0.03;

elseif(i=1e6)bonus=bon6+(i-600000)*0.015;

elsebonus=bon10+(i-1000000)*0.01;

printf("bonus=.2f",bonus);

用switch句子编程序

main()

{longi;

floatbonus,bon1,bon2,bon4,bon6,bon10;

intbranch;

bon1=100000*0.1;

bon2=bon1+100000*0.075;

bon4=bon2+200000*0.05;

bon6=bon4+200000*0.03;

bon10=bon6+400000*0.015;

scanf("%ld",i);

branch=i/100000;

if(branch10)branch=10;

switch(branch)

{case0:bonus=i*0.1;break;

case1:bonus=bon1+(i-100000)*0.075;break;

case2:

case3:bonus=bon2+(i-200000)*0.05;break;

case4:

case5:bonus=bon4+(i-400000)*0.03;break;

case6:

case7

case8:

case9:bonus=bon6+(i-600000)*0.015;break;

case10:bonus=bon10+(i-1000000)*0.01;

printf("bonus=.2f",bonus);

5.9输入四个整数,按大小次序输出.

main()

{intt,a,b,c,d;

printf("请输入四个数:");

scanf("%d,%d,%d,%d",a,b,c,d);

printf("\n\na=%d,b=%d,c=%d,d=%d\n",a,b,c,d);

if(ab)

{t=a;a=b;b=t;}

if(ac)

{t=a;a=c;c=t;}

if(ad)

{t=a;a=d;d=t;}

if(bc)

{t=b;b=c;c=t;}

if(bd)

{t=b;b=d;d=t;}

if(cd)

{t=c;c=d;d=t;}

printf("\n排序结果如下:\n");

printf("%d%d%d%d\n",a,b,c,d);

5.10塔

main()

inth=10;

floatx,y,x0=2,y0=2,d1,d2,d3,d4;

printf("请输入一个点(x,y):");

scanf("%f,%f",x,y);

d1=(x-x0)*(x-x0)+(y-y0)(y-y0);

d2=(x-x0)*(x-x0)+(y+y0)(y+y0);

d3=(x+x0)*(x+x0)+(y-y0)*(y-y0);

d4=(x+x0)*(x+x0)+(y+y0)*(y+y0);

if(d11d21d31d41)

h=0;

printf("该点高度为%d",h);

c语言程序设计实验指导与