时间:2011-12-25 00:30:33
第31套题
一、程序填空题
#include <stdio.h>
#define N 3
#define M 4
/**********found**********/
void fun(int (*a)[N], int __1__)
{ int i,temp ;
/**********found**********/
for(i = 0 ; i < __2__ ; i++)
{ temp=a[0][i] ;
/**********found**********/
a[0][i] = __3__ ;
a[k][i] = temp ;
}
}
main()
{ int x[M][N]={ {1,2,3},{4,5,6},{7,8,9},{10,11,12} },i,j;
printf("The array before moving:nn");
for(i=0; i<M; i++)
{ for(j=0; j<N; j++) printf("%3d",x[i][j]);
printf("nn");
}
fun(x,2);
printf("The array after moving:nn");
for(i=0; i<M; i++)
{ for(j=0; j<N; j++) printf("%3d",x[i][j]);
printf("nn");
}
}
二、程序改错题
#include <stdio.h>
#include <string.h>
void fun( char t[] )
{
char c;
int i, j;
/**********found***********/
for( i = strlen( t ); i; i-- )
for( j = 0; j < i; j++ )
/**********found***********/
if( t[j] < t[ j + 1 ] )
{
c = t[j];
t[j] = t[ j + 1 ];
t[j + 1 ] = c;
}
}
main()
{
char s[81];
printf( "nPlease enter a character string: " );
gets( s );
printf( "nnBefore sorting:n "%s"", s );
fun( s );
printf( "nAfter sorting decendingly:n "%s"n", s );
}
三、程序编写题
#include <stdio.h>
#include <string.h>
void fun( char *ss )
{
}
void main( void )
{
char tt[51];void NONO ();
printf( "nPlease enter an character string within 50 characters:n" );
gets( tt );
printf( "nnAfter changing, the stringn "%s"", tt );
fun(tt) ;
printf( "nbecomesn "%s"", tt );
NONO();
}
void NONO ()
{
/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,
输出数据,关闭文件。 */
char tt[51], ch;
FILE *rf, *wf ;
int len, i=0 ;
rf = fopen("K:\k01\24010001\in.dat","r") ;
wf = fopen("K:\k01\24010001\out.dat","w") ;
while(i < 10) {
fgets( tt, 50, rf );
len = strlen(tt) - 1 ;
ch = tt[len] ;
if(ch == 'n' || ch == 0x1a) tt[len] = 0 ;
fun(tt);
fprintf( wf, "%sn", tt );
i++ ;
}
fclose(rf) ;
fclose(wf) ;
}