时间:2011-12-25 00:18:09
第23套题
一、程序填空题
#include <stdio.h>
unsigned long fun(unsigned long n)
{ unsigned long x=0, s, i; int t;
s=n;
/**********found**********/
i=__1__;
/**********found**********/
while(__2__)
{ t=s%10;
if(t%2==0){
/**********found**********/
x=x+t*i; i=__3__;
}
s=s/10;
}
return x;
}
main()
{ unsigned long n=-1;
while(n>99999999||n<0)
{ printf("Please input(0<n<100000000): "); scanf("%ld",&n); }
printf("nThe result is: %ldn",fun(n));
}
二、程序改错题
#include <stdio.h>
#define M 5
/************found************/
int fun(int n, int xx[][])
{ int i, j, sum=0;
printf( "nThe %d x %d matrix:n", M, M );
for( i = 0; i < M; i++ )
{ for( j = 0; j < M; j++ )
/************found************/
printf( "%f ", xx[i][j] );
printf("n");
}
for( i = 0 ; i < n ; i++ )
sum += xx[i][i]+xx[i][ n-i-1 ];
return( sum );
}
main( )
{ int aa[M][M]={{1,2,3,4,5},{4,3,2,1,0},
{6,7,8,9,0},{9,8,7,6,5},{3,4,5,6,7}};
printf ( "nThe sum of all elements on 2 diagnals is %d.",fun( M, aa ));
}
三、程序编写题
#include <stdio.h>
void fun(int a, int b, long *c)
{
}
main()
{ int a,b; long c;void NONO ();
printf("Input a b:");
scanf("%d%d", &a, &b);
fun(a, b, &c);
printf("The result is: %ldn", c);
NONO();
}
void NONO ()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *rf, *wf ;
int i, a,b ; long c ;
rf = fopen("K:\k01\24010001\in.dat","r") ;
wf = fopen("K:\k01\24010001\out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%d,%d", &a, &b) ;
fun(a, b, &c) ;
fprintf(wf, "a=%d,b=%d,c=%ldn", a, b, c) ;
}
fclose(rf) ;
fclose(wf) ;
}