C语言程序设计苏小红版答案解析_第1页
C语言程序设计苏小红版答案解析_第2页
C语言程序设计苏小红版答案解析_第3页
C语言程序设计苏小红版答案解析_第4页
C语言程序设计苏小红版答案解析_第5页
已阅读5页,还剩93页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、完美WORD格式2.2 #includemain()floatx=2.5,y=2.5,z=2.5;printf(x=%fn,x);printf(y=%fn,y);printf(z=%fn,z);3.1 (1)#includemain()inta=12,b=3;floatx=18.5,y=4.6;printf(%dn,(float)(a*b)/2);printf(%dn,(int)x%(int)y);3.2 #includemain()intx,b0,b1,b2,s;printf(Inputx:);scanf(%d,&x);b2=x/100;b1=(x-b2*100)/10;b0=x%10;s=

2、b0*100+b1*10+b2;printf(s=%dn,s);3.3 #include#includemain()floatrate=0.0225;floatn,capital,deposit;printf(Inputn,capital:);scanf(%f,%f,&n,&capital);deposit=capital*pow(1+rate,n);printf(deposit=%fn,deposit);3.4 #include#includemain()floata,b,c;doublex,y;printf(Inputa,b,c:);scanf(%f,%f,%f,&a,&b,&c);x=(

3、-b+sqrt(b*b-4*a*c)/(2*a);y=(-b-sqrt(b*b-4*a*c)/(2*a);printf(x=%f,y=%fn,x,y);4.1(1)#includemain()charc1=a,c2=b,c3=c;printf(a%cb%cc%cn,c1,c2,c3);4.1(2)#includemain()inta=12,b=15;printf(a=%d%,b=%d%n”,a,b);4.1 (3)#includemain()inta,b;scanf(%2d%*2s%2d”,&a,&b);printf(%d,%dn,a,b);4.2 #includemain()longa,b;

4、floatx,y;scanf(%d,%dn,&a,&b);scanf(%f,%fn,&x,&y);printf(a=%d,b=%dn,a,b);printf(x=%f,b=%fn,x,y);5.1 #includemain()floata;printf(Innputa:);scanf(%f,&a);if(a=0)完美WORD格式a=a;printf(a=%fn,a);elsea=-a;printf(a=%fn,a);5.2 #includemain()inta;printf(Inputa:);scanf(%d,&a);if(a%2=0)printf(a是偶数);elseprintf(a是奇数)

5、;5.3 #include#includemain()floata,b,c,s,area;printf(Inputa,b,c:);scanf(%f,%f,%f,&a,&b,&c);if(a+bc&a+cb&b+ca)s=(a+b+c)/2;area=(float)sqrt(s*(s-a)*(s-b)*(s-c);printf(area=%fn,area);else完美WORD格式printf(不是三角形);5.4 #include#includemain()floata,b,c,x,y;printf(Inputa,b,c:);scanf(%f,%f,%f,&a,&b,&c);if(a=0)pr

6、intf(该方程不是一元二次方程n);if(b*b-4*a*c0)x=(-b+sqrt(b*b-4*a*c)/(2*a);y=(-b-sqrt(b*b-4*a*c)/(2*a);printf(x=%f,y=%fn,x,y);elseif(b*b-4*a*c=0)x=-b/(2*a);y=-b/(2*a);printf(x=%f,y=%fn,x,y);elseprintf(该方程无实根n);5.5 #includemain()intyear,flag;printf(Inputayear:);scanf(%d,&year);if(year%4=0&year%400!=0|year%400=0)fl

7、ag=1;elseflag=0;if(flag=1)printf(%disaleapyear!n,year);elseprintf(%disnotaleapyear!n,year);5.6 #includemain()intyear,flag;printf(Inputayear:);scanf(%d”,&year);flag=year%400=0|year%4=0&year%100!=0?1:0;if(flag=1&flag!=0)printf(%disaleapyear!n,year);elseprintf(%disnotaleapyear!n,year);5.7 #includemain(

8、)charch;printf(Inputch:);scanf(%c”,&ch);if(ch=a&ch=A&ch=Z)ch=getchar();ch=ch+32;printf(%c,%dn,ch,ch);elseprintf(%c,ch);专业知识分享完美WORD格式5.8 #includemain()charch;printf(Inputch:);scanf(%c”,&ch);if(ch=48&ch=65&ch=97&ch=122)printf(ch是小写字母n);elseif(ch=32)printf(ch是空格n);elseprintf(ch是其他字符n);5.9 #includemain

9、()intscore,grade;printf(Inputscore:);scanf(%d,&score);grade=score/10;if(score100)printf(Input errorn);if(score=90&score=80&score=70&score=60&score=0&score60)printf(%d-En,score);5.10 #includemain()intyear,month;printf(Inputyear,month:);scanf(%d,%d,&year,&month);if(month12|month=0)printf(errormonthn);

10、elseswitch(year,month)case12:case10:case8:case7:case5:case3:printf(31 天 n);break;case I: case9:case6:case4:printf(30天n);break;专业知识分享完美WORD格式case2:if(year%4=0&year!=0|year%400=0)printf(29天n);elseprintf(28天n);break;default:printf(Inputerrorn);6.1(1)#includemain()inti,j,k;charspace=;for(i=1;i=4;i+)for(

11、j=1;j=i;j+)printf(%c,space);for(k=1;k=6;k+)printf(*);printf(n);6.1(2)#includemain()intk=4,n;for(n=0;nk;n+)if(n%2=0)continue;k-;printf(k=%dn,n=%dn,k,n);专业知识分享完美WORD格式6.1(3)#includemain()intk=4,n;for(n=0;nk;n+)if(n%2=0)break;k-;printf(k=%d,n=%dn,k,n);6.2(1)#includemain()inti,sum=0;for(i=1;i=101;i+)sum

12、=sum+i;printf(sum=%dn,sum);6.2(2)#includemain()longi;longterm,sum=0;for(i=1;i=101;i=i+2)term=i*(i+1)*(i+2);sum=sum+term;printf(sum=%ldn,sum);6.2(4)#include#includemain()intn=1;floatterm=1.0,sign=1,sum=0;while(term=1e-4)(term=1.0/sign;sum=sum+term;sign=sign+n;n+;printf(sum=%fn,sum);6.2 (5)#include#in

13、cludemain()intn=1,count=1;floatx;doublesum,term;printf(Inputx:);scanf(%f,&x);sum=x;term=x;doterm=-term*x*x/(n+1)*(n+2);sum=sum+term;n=n+2;count+;while(fabs(term)=1e-5);printf(sin(x)=%f,count=%dn,sum,count);6.3 #includemain()intx=1,find=0;while(!find)if(x%2=1&x%3=2&x%5=4&x%6=5&x%7=0)printf(x=%dn,x);f

14、ind=1;x+;/*intx,find=0;for(x=1;!find;x+)(if(x%2=1&x%3=2&x%5=4&x%6=5&x%7=0)(printf(x=%dn,x);find=1;*/6.4 #includemain()inti,n;longp=1,m=1;printf(Inputn:);scanf(%d,&n);for(i=1;i=n;i+)p=i*i;m=i*i*i;printf(p=%d,m=%dn,i,p,i,m);6.5 #includemain()floatc,f;for(c=-40;c=110;c=c+10)f=9/5*c+32;printf(f=%fn,f);6

15、.6 #include#includemain()intn;doublec=0.01875,x;dox=x*pow(1+c,12)-1000;n+;完美WORD格式while(x0);printf(x=%dn,x);6.7 #includemain()intn=0;sum=sum+term;floata=100.0,c;printf(Inputc:);scanf(%f,&c);doa=a*(1+c);n+;while(a=200);printf(n=%dn,n);6.8 #include#includemain()intn=1,count=1;doublesum=1,term=1;while(

16、fabs(term)=1e-5)term=pow(-1,count)*(1.0/(n+2);sum=sum+term;n=n+2;count+;sum=4*sum;printf(sum=%f,count=%dn,sum,count);6.9 #include#includemain()intn=1,count=1;doublesum=1,term=1;while(fabs(term)=1e-5)term=term*(1.0/n);n+;count+;printf(sum=%f,count=%dn,sum,count);6.10 #include#include完美WORD格式main()int

17、x;for(x=100;x=999;x+)if(x=pow(x/100,3)+pow(x/10%10,3)+pow(x%10,3)printf(x=%dn,x);6.11 #includemain()inti=0,n;longsum=0,term=1;printf(Inputn:);scanf(%d,&n);doi+;term=term*i;sum=sum+term;while(sumn);printf(%dn,i-1);6.12 #includemain()inti,n,m,count=0,sum=0;printf(Inputn:);scanf(%d,&n);for(i=1;i0)sum=s

18、um+m;完美WORD格式count+;elsebreak;printf(sum=%d,count=%dn,sum,count);6.13 #includemain()inti,n,m,count=0,sum=0;printf(Inputn:);scanf(%d,&n);for(i=1;i0|m0)sum=sum+m;count+;elsebreak;printf(sum=%d,count=%dn,sum,count);6.14 #includemain()intx,y,z;for(x=0;x=17;x+)for(y=0;y=25;y+)3*x+2*y+z=50;z=30-x-y;if(3*x

19、+2*y+z=50&x+y+z=30)printf(x=%d,y=%d,z=%dn,x,y,z);6.15 #includemain()intx,y;for(x=0;x=98;x+)完美WORD格式(y=98-x;2*x+4*y=386;if(x+y=98&2*x+4*y=386)(printf(x=%d,y=%dn,x,y);)6.16 #includemain()(intx,y,z;for(x=0;x=20;x+)(for(y=0;y=33;y+)(3*y+5*x+z/3.0=100;z=100-x-y;if(5*x+3*y+z/3.0=100&z+x+y=100)(printf(x=%d

20、,y=%d,z=%dn,x,y,z);)6.17 #includemain()(intx,y,z;for(x=1;x=9;x+)(for(y=1;y0)(printf(x=%d,y=%d,z=%dn,x,y,z);)专业知识分享完美WORD格式7.1#includeintSquare(inti)returni*i;intmain()inti=0;i=Square(i);for(;i3;i+)staticinti=1;i+=Square(i);printf(%d,”,i);printf(%dn,i);return0;7.2 #includeinthour,minute,second;voidup

21、date()second+;if(second=60)second=0;minute+;if(minute=60)minute=0;hour+;if(hour=24)hour=0;完美WORD格式voiddisplay()printf(%d,%d,%dn,hour,minute,second);voiddelay()intt;for(t=0;t100000000;t+);intmain()inti;voidupdaye(),display(),delay();for(i=0;i1000000;i+)update();display();delay();return0;7.3 #includei

22、ntGetMax(inta,intb);intmain()intx,y,max;printf(Inputx,y:);scanf(%d,%d,&x,&y);max=GetMax(x,y);printf(max=%dn,max);return0;intGetMax(intm,intn)if(m=n)returnm;elsereturnn;7.4 #includeintLCM(intn,intm);intmain()inta,b;printf(Inputa,b:);scanf(%d,%d,&a,&b);printf(%dn,LCM(a,b);return0;intLCM(intn,intm)完美WO

23、RD格式intx;intfind=0;for(x=1;!find;x+)if(x%n=0&x%m=0)find=1;returnx-1;7.5 #includelongFact(intn);intmain()intm,a;printf(Inputm:);scanf(%d,&m);for(a=1;a=m;a+)printf(%d!=%ldn,a,Fact(a);return0;longFact(intn)inti;longresult=1;for(i=2;i=n;i+)result*=i;returnresult;7.6 #includelongFact(intn);int main()intm

24、;longret;printf(Inputm:);scanf(%d,&m);ret=Fact(m);printf(ret=%dn,ret);专业知识分享完美WORD格式return0;longFact(intn)inti;longresult=1,sum=0;for(i=2;i=n;i+)result*=i;sum=sum+result;returnsum;7.7 (1)#includeintGcd(inta,intb);intmain()intm,n;printf(Inputm,n:);scanf(%d,%d,&m,&n);printf(%dn,Gcd(m,n);return0;intGcd

25、(inta,intb)intt,min,find=0;min=ab?a:b;t=min;for(t=min;!find;t-)a%t=0;b%t=0;if(a%t=0&b%t=0)returnt;find=1;完美WORD格式7.8 (2)#includeintGcd(inta,intb);intmain()intm,n;printf(Inputm,n:);scanf(%d,%d,&m,&n);printf(%dn,Gcd(m,n);return0;intGcd(inta,intb)intr,temp;r=a%b;if(r=0)returnb;elsedotemp=b;b=r;a=temp;r

26、=a%b;while(r!=0);returnb;8.1(1)#includevoidFunc(intx)x=2;intmain()intx=10;Func(x);printf(%d,x);return0;8.1 (2)#includevoidFunc(intb)intj;for(j=0;j4;j+)bj=j;intmain()staticinta=5,6,7,8,i;Func(a);for(i=0;i4;i+)printf(%d,ai);return0;8.2 (1)intPositiveNum(inta,intn)inti,count=0;for(i=0;i0)count+;return0

27、;8.3 (2)voidFib(longf,longn)inti;f0=0;f1=1;for(i=2;in;i+)fi=fi-1+fi-2;8.4 (3)#includeintmain()inta10,n,max,min,maxPos,minPos;for(n=0;n10;n+)scanf(%d”,&an);max=min=a0;maxPos=minPos=0;for(n=0;nmax)max=an;maxPos=n;elseif(ankmin)min=an;专业知识分享完美WORD格式minPos=n;printf(max=%d,pos=%dn,max,maxPos);printf(min=

28、%d,pos=%dn,min,minPos);return0;8.5 voidDivArray(int*pArray,intn)inti;for(i=0;in;i+)pArrayi/=pAttay0;8.6 #include#defineN40intFailNum(intscore口,intn);voidReadScore(intscore,intn);intmain()intscoreN,n;printf(Inputn:);scanf(%d,&n);ReadScore(score,n);FailNum(score,n);printf(FailNumstudentsare%dn,FailNum

29、(score,n);return0;intFailNum(intscore口,intn)inti,count=0;for(i=0;in;i+)if(scorei60)count+;returncount;voidReadScore(intscore,intn)inti;printf(Inputscore:);for(i=0;in;i+)专业知识分享完美WORD格式scanf(%d”,&scorei);8.7 #include#defineN40intHighAver(intscore,intn);intReadScore(intscore);intmain()intscoreN,n;n=ReadScore(score);printf(HighAverstudentsare%dn”,HighAver(score,n);return0;intHighAver(intscore,intn)inti,count=0,sum=0,aver;for(i=0;in;i+)sum=sum+scorei;aver=sum/n;for(i=0;iaver)count+;returncount;intReadScore(intscore)inti=-1;doi+;printf(Inputscore:);scanf(%d”

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论