微信搜索关注"91考试网"公众号,领30元,获取公务员、事业编、教师等考试资料40G!
第15套题
一、程序填空题
#include <stdio.h>
void fun(char *s)
{ int i, n, k; char c;
n=0;
for(i=0; s[i]!='\0'; i++) n++;
/**********found**********/
if(n%2==0) k=n-___1___ ;
else k=n-2;
/**********found**********/
c=___2___ ;
for(i=k-2; i>=1; i=i-2) s[i+2]=s[i];
/**********found**********/
s[1]=___3___ ;
}
main()
{ char s[80]="abcdefgh";
printf("\nThe original string is : %s\n",s);
fun(s);
printf("\nThe result is : %s\n",s);
}
二、程序改错题
#include <stdio.h>
long fun (int a, int n)
{ int j ;
/**************found**************/
long s = 0, t = 1 ;
for ( j = 0 ; j < n ; j++)
t = t * 10 + a ;
s = t ;
for ( j = 1 ; j < n ; j++) {
/**************found**************/
t = t % 10 ;
s = s - t ;
}
return(s) ;
}
main( )
{ int a, n ;
printf( "\nPlease enter a and n:") ;
scanf( "%d%d", &a, &n ) ;
printf( "The value of function is: %ld\n", fun ( a, n ) );
}
三、程序编写题
#include <stdio.h>
#include <string.h>
void fun(char *tt, int pp[])
{
}
main( )
{ char aa[1000] ;
int bb[26], k ;
void NONO ( );
printf( "\nPlease enter a char string:" ) ; scanf("%s", aa) ;
fun(aa, bb ) ;
for ( k = 0 ; k < 26 ; k++ ) printf ("%d ", bb[k]) ;
printf( "\n" ) ;
NONO ( ) ;
}
void NONO ( )
{/* 本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/
char aa[1000] ;
int bb[26], k, i ;
FILE *rf, *wf ;
rf = fopen("K:\\k01\\24010001\\in.dat","r") ;
wf = fopen("K:\\k01\\24010001\\out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%s", aa) ;
fun(aa, bb) ;
for ( k = 0 ; k < 26 ; k++ ) fprintf (wf, "%d ", bb[k]) ;
fprintf(wf, "\n" ) ;
}
fclose(rf) ;
fclose(wf) ;
}