A-A+

试题3本程序中 函数fun的功能是判断字符串是否是回文 若是回文 则返回1 主函数中输出YES;否则 函

2020-10-12 15:11:45 IT认证 阅读

问题详情

试题3

本程序中,函数fun的功能是判断字符串是否是回文,若是回文,则返回1,主函数中输出YES;否则,函数返回0,主函数中输出NO。回文是指顺读和倒读都一样的字符串。例如,字符串LEVEL是回文,而123312就不是回文。请在函数fun的花括号中填入你编写的若干语句。(注意:不改动程序的结构,不得增行或删行。)

#include <stdio.h>

#define N 80

int fun (char *str)

{

}

main()

{ char s[N];

printf(“Enter a string : ”) ;

gets (s) ;

printf(“ ”) ;

puts (s) ;

if (fun (s))

printf (“YES ”) ;

else

printf (“N0 ”) ;

nono ();

}

nono ()

{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件.*/

int i;

FILE *rf, *wf ;

char s[N] ;

rf = fopen (“bc.in”,“r”) ;

wf = fopen (“bc.out”,“w”) ;

for (i=0; i<10; i++ )

{ fscanf (rf, “%s”,s ) ;

if (fun (s ))

fprintf (wf, “%s YES ”, s ) ;

Else

fprintf(wf, “%s NO ”, s ) ;

}

fclose (rf) ;

fclose (wf) ;

}

参考答案

考点: