- 1、本文档共24页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
(C语言)上机部分试题.doc
二级考试(C语言)上机部分试题
1.三个数比较大小。
#include stdio.h
void swap(______1______) //int *pa,int *pb
{ /*交换两个数的位置*/
int temp; temp = *pa; *pa = *pb; *pb = temp; }
void main()
{ int a,b,c,temp;
scanf(%d%d%d,a,b,c);
if(ab) swap(a,b);
if(bc) swap(b,c);
if(______2______) //ab
swap(a,b);
printf(%d,%d,%d,a,b,c); }
2.表达式求和。
#include stdio.h #include math.h
void main()
{ FILE *fp;
float n=1,t=1,pi=0;
int i;
// 以下开始做答
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); }
运行结果:3.141594
3.字母后移循环输出。
#include stdio.h
void main()
{ char c; c=getchar();
if(______1______) // c=a cv
c=c+5;
else
if (c=v c=z)
______2______ // c=c-21;
putchar(c); }
4.求满足条件的数。
#include stdio.h
#include math.h
void main()
{ float y=1.05; int n=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,992137
5.求满足条件的数。
#include stdio.h
void main()
{ int m=0,t=1,n;
while( _____ 1 ________); // (scanf(%d,n),n=0)
while(!(t=nt*2=n)){
_____ 2 _____ // t=t*2;
m++; }
printf(%d\n,m); }
6.求平面点间的最短距离。
#include stdio.h #include math.h
#define len(x1,y1,x2,y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
void main()
{ FILE *p; int i,j; float c,minc;
float x[]={1.1,3.2,-2.5,5.67,3.42,-4.5,2.54,5.6,0.97,4.65};
float y[]={-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;i9;i++)
for(j=i+1;j10;j++)
if((c=len(x[i],y[i],x[j],y[j]))minc)
minc=c;
fprintf(p,%f,minc);
fclose(p); }
运行结果:1.457944
7.Fibonacci数列求值问题。
#include stdio.h
_______1______ // long f(int n);
void main()
{ printf(%ld\n,f(30)); }
long f(int n)
{ if( ______2______ ) // n==1 || n==2
return
文档评论(0)