C语言程序设计配套习题-带答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1《C语言程序设计》配套习题集答案2010-5-10目录概述.....................................................................................................................................2类型、运算符与表达式...................................................................................................19分支结构...........................................................................................................................21循环结构...........................................................................................................................26函数...................................................................................................................................36数组...................................................................................................................................46C预处理器.......................................................................................................................59指针...................................................................................................................................60结构...................................................................................................................................65位运算...............................................................................................................................76文件...................................................................................................................................772概述一、单项选择题。12345678910DBAACDBABB11121314151617181920A此题删除CABCCCCC21A二、程序设计题。1.#includestdio.hintmain(){printf(%d\n,EOF);return0;}2.#includestdio.hintmain(){inta,b;/*变量的声明*/scanf(%d%d,&a,&b);/*输入两个整数*//*求两个整数的和,乘积,差和商,并且输出*/printf(%d%d%d%d\n,a+b,a*b,a-b,a/b);return0;}3.#includestdio.h#includemath.hintmain()3{doublex1,y1,x2,y2;doublea,b,c;scanf(%lf%lf%lf%lf,&x1,&y1,&x2,&y2);a=(x1-x2)*(x1-x2);b=(y1-y2)*(y1-y2);c=sqrt(a+b);printf(%.2lf\n,c);return0;}4./*countblanks,tabs,andnewlines*/#includestdio.hintmain(){intc,nb=0,nt=0,nl=0;while((c=getchar())!=EOF){if(c=='')++nb;if(c=='\t')++nt;if(c=='\n')++nl;}printf(%d%d%d\n,nb,nt,nl);return0;}5.#includestdio.h#includemath.hintmain(){inti=1;while(!(i%3==1&&i%5==3&&i%7==5&&i%9==7))i++;printf(%d\n,i);return0;}46.#includestdio.h#includemath.hintmain(){inti;doublesum=0;for(i=2;i=10;i++)sum=sum+sqrt(i);printf(%.10f\n,sum);return0;}7.#includestdio.hintmain(){floats=100,h=100;inti;h=s/2;for(i=2;i=10;i++){s=s+2*h;h=h/2;}printf(%.2f\n,s);return0;}8.#includestdio.h#includemath.hintmain(){floats=1,t=1,i=3;while(fabs(1/t)=1e-6){t=-t*(i-1)*i;s=s+1/t;i+=2;}printf(%f\n,s);return0;5}9.#includestdio.h#includemath.hintmain(){doublet=1,sum=1,pi=0;inti=1,k=1;while(fabs(t)=1e-6){i=i+2;t=1.0/i;k=-k;sum=sum+k*t;}pi=4*sum;printf(%f\n,pi);return0;}10.#includestdio.h#includemath.hintmain(){doublex=27;intn=2;while(!(pow(27,1.0/(2*n))1.00001&&pow(27,1.0/(2*(n-1)))1.00001))n++;printf(%d\n,n);return0;}11.#includestdio.h#includemath.hintmain(){floaty=1.05;intn=1;while(!(pow(1.05,n)1e6&&pow(1.05,n+1)1e6))n++;printf(%d,%.3f\n,n,pow(1.05,n));6return0;}12.#includestdio.h#includemath.hintmain(){doubles=0,a=81;inti;for(i=1;i=30;i++){s=s+a;a=sqrt(a);}printf(%.3f\n,s);return0;}13.#includestdio.hintmain(){inta,b,i;intasum,bsum;for(a=6;a=5000;a++){asum=0;for(i=1;ia;i++)/*求a的因子之和asum*/if(a%i==0)asum=asum+i;b=asum;/*a的因子和等于b*/bsum=0;for(i=1;ib;i++)/*求b的因子之和bsum*/if(b%i==0)bsum=bsum+i;/*判断b的因子和是否等于a,并且a不等于b*/if(bsum==a&&a!=b)printf(%d,%d\n,a,b);}7return0;}14.#includestdio.h#includemath.hintmain(){intx,y,x1,y1;doublez,z1;z1=10*cos(0-4)+5*sin(0-2);x1=0;y1=0;for(x=0;x=10;x++)for(y=0;y=10;y++){z=10*cos(x-4)+5*sin(y-2);if(zz1){z1=z;x1=x;y1=y;}}printf(%d,%d\n,x1,y1);return0;}15.#includestdio.hintmain(){inta,b,c;intcount=0;for(a=1;a=100;a++)for(b=1;b=100;b++)for(c=1;c=100;c++)if((a*a+b*b)==c)/*注意不要写成c/(a*a+b*b)==1*/count++;printf(%d\n,count);return0;}16.8#includestdio.h#includemath.hintmain(){intx,y,z,rslnum=0;intk=(int)sqrt(2000);for(x=-k;x=k;x++)for(y=-k;y=k;y++)for(z=-k;z=k;z++)if(x*x+y*y+z*z==2000)rslnum++;printf(%d\n,rslnum);return0;}17.#includestdio.h#includemath.hfloatf(float);intmain(){floatmax,x;max=f(1);for(x=2;x=10;x++)if(f(x)max)max=f(x);printf(%.3f\n,max);return0;}floatf(floatx){returnx-10*cos(x)-5*sin(x);}18.#includestdio.hdoublef(intx,inty);intmain(){doublemin;intx,y,x1,y1;min=f(1,1);9for(x=1;x=6;x++){for(y=1;y=6;y++)if(f(x,y)min){min=f(x,y);x1=x;y1=y;}}printf(%d,%d\n,x1,y1);return0;}doublef(intu,intv){return(3.14*u-v)/(u+v);}19.#includestdio.h#includestdlib.h#includestring.hintJSValue(longm){intk,n;n=m;k=0;while(m){k=k*10+m%10;m/=10;}if(k==n)return1;elsereturn0;}intmain(){longm;for(m=11;m1000;m++)if(JSValue(m)&&JSValue(m*m)&&JSValue(m*m*m))printf(%ld%ld%ld\n,m,m*m,m*m*m);10return0;}20.#includestdio.h#defineP11.5#defineY1999intYear(doublex){intnumber=Y;doubleyield=P;while(yieldx){yield=yield*(1+9.8/100);number++;}returnnumber;}intmain(){doublex;scanf(%lf,&x);printf(%d\n,Year(x)

1 / 87
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功