资源描述:
《浙江省2011年秋季C语言二级考试上机编程试题及答案.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、浙江省2011年秋季C语言二级考试上机编程试题及答案1.三个数比较大小。#includevoidswap(______1______)//int*pa,int*pb{/*交换两个数的位置*/inttemp;temp=*pa;*pa=*pb;*pb=temp;}voidmain(){inta,b,c,temp;scanf("%d%d%d",&a,&b,&c);if(a>b)swap(&a,&b);if(b>c)swap(&b,&c);if(______2______)//a>bswap(&a,&b);printf("%d,%d,%d",a,b,c);}2.表达式求和。#in
2、clude#includevoidmain(){FILE*fp;floatn=1,t=1,pi=0;inti;//从以下开始答题i=1;while(fabs(t)>=1e-6){pi=pi+t;i=-i;n=n+2;t=i/n;}fp=fopen("Design1.dat","w");fprintf(fp,"%.6f",4*pi);fclose(fp);}29运行结果:3.3.字母后移循环输出。#includevoidmain(){charc;c=getchar();if(______1______)//c>='a'&&c<'v'c=c+
3、5;elseif(c>='v'&&c<='z')______2______//c=c-21;putchar(c);}4.求满足条件的数。#include#includevoidmain(){floaty=1.05;intn=1;FILE*p;//以下开始做答while(!(pow(y,n)<1e6&&pow(y,n+1)>1e6))n++;p=fopen("Design2.dat","w");fprintf(p,"%d,%.0f",n,pow(1.05,n));fclose(p);}运行结果:283,295.求满足条件的数。#include4、>voidmain(){intm=0,t=1,n;while(_____1________);//(scanf("%d",&n),n<=0)while(!(t<=n&&t*2>=n)){_____2_____//t=t*2;m++;}printf("%d",m);}6.求平面点间的最短距离。#include#include#definelen(x1,y1,x2,y2)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))voidmain(){FILE*p;inti,j;floatc,minc;floatx[]={1.1,3.2,-2
5、.5,5.67,3.42,-4.5,2.54,5.6,0.97,4.65};floaty[]={-6,4.3,4.5,3.67,2.42,2.54,5.6,-0.97,4.65,-3.33};minc=len(x[0],y[0],x[1],y[1]);p=fopen("Design1.dat","w");for(i=0;i<9;i++)for(j=i+1;j<10;j++)if((c=len(x[i],y[i],x[j],y[j]))6、e_______1______//longf(intn);voidmain(){printf("%ld",f(30));}longf(intn){if(______2______)//n==1
7、
8、n==2return1;elsereturnf(n-1)+f(n-2);}运行结果:8.多项式求和问题。#include#includevoidmain(){FILE*p;inti;floatx=1.279,t=1,y=0;floata[10]={1.1,3.2,-2.5,5.67,3.42,-4.5,2.54,5.6,0.97,4.65};
9、p=fopen("Design2.dat","w");y=a[0];for(i=1;i<10;i++){t=t*x;y=y+t*a[i];}fprintf(p,"%f",y);fclose(p);}运行结果:98.299.整数转换为字符串。#includevoiditoa(longi,char*s){if(i==0)return;/******1******/*s='1'+i%10;//*s='0'+i