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(a〉b) swap(&a,&b); if(b>c) swap(&b,&c); if(______2______) //a〉b swap(&a,&b);
printf(”%d,%d,%d”,a,b,c); } 2.表达式求和。
#include 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' && c〈’v' c=c+5; else
if (c>='v' && c<=’z’)
______2______ // c=c-21; putchar(c); } 4.求满足条件的数。 #include 〈stdio.h> #include void main(){ float y=1.05; int n=1; FILE *p; // 以下开始做答 while(!(pow(y,n)<1e6 && pow(y,n+1)〉1e6)) n++;
1
p=fopen(”Design2。dat”,”w”);
fprintf(p,”%d,%.0f\",n,pow(1。05,n)); fclose(p); } 运行结果:283,992137 5.求满足条件的数。 #include void main(){ int m=0,t=1,n;
while( _____ 1 ________); // (scanf(\"%d\",&n),n〈=0) while(!(t〈=n&&t*2>=n)){
_____ 2 _____ // t=t*2; m++; }
printf(\"%d\\n”,m); } 6.求平面点间的最短距离。
#include #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;i〈9;i++)
for(j=i+1;j〈10;j++) if((c=len(x[i],y[i],x[j],y[j]))fprintf(p,\"%f”,minc); fclose(p); } 运行结果:1.4579447.Fibonacci数列求值问题。 #include _______1______ // long f(int n); void main(){ printf(”%ld\\n\(30)); } long f(int n)
{ if( ______2______ ) // n==1 || n==2 return 1; else
return f(n—1)+f(n—2); } 运行结果:832040
8.多项式求和问题。
#include #include 〈math.h〉 void main(){ FILE *p; int i; float x=1.279,t=1,y=0;
float a[10]={1。1,3.2,—2.5,5.67,3.42,—4.5,2。54,5.6,0。97,4。65}; p=fopen(\"Design2。dat\); y=a[0] ;
2
for(i=1;i〈10;i++)
{ t=t*x; y=y+t*a[i]; } fprintf(p,”%f”,y); fclose(p); } 运行结果:98。722542 9.整数转换为字符串。 #includevoid itoa(long i,char *s) { if(i==0) return; /****** 1 ******/ *s = '1'+i%10; //*s='0’+i%10 itoa(i/10,s—1); } void main()
{ long n; char str[7]=”\"; scanf(\"%ld\",&n); /****** 2 ******/ itoa(n,str+6); // itoa(n,str+5); printf(\"%s\ }
10.Fibonacci数列求值问题。 #include〈stdio。h> void main()
{ FILE *p; int i; float f1=1.0,f2=2.0,t1=2.0,t2=3。0,s; float f,t;
s=t1/f1+t2/f2;
p=fopen(\"Design1.dat\ for(i=3;i〈40;i=i+2)
{ t1=t1+t2; t2=t1+t2; f1=f1+f2; f2=f1+f2; s=s+t1/f1+t2/f2; } fprintf(p,”%.6f”,s); fclose(p); } 运行结果:65.020950 11.数组赋值。 #include void main(){ int a[10],b[10],i;
printf(”\\ninput 10 numbers: ”);
for (i=0; i〈10;i++) /* 数组输入 */ scanf(”%d”, &a[i]); for (i=1; i〈10; i++)
b[i]=______1______; // b[i]=a[i]+a[i-1]; for (i=1; i〈10; i++) { printf(\"%3d\",b[i]);
if (______2______) printf(\"\\n\"); // i%3==0 } } 12.求各点距离和。
#include〈stdio.h> #include