问答题
给定程序中,函数fun的功能是:判断形参s所指字符串是否是"回文"(Palindrome),若是,函数返回值为1;不是,函数返回值为0。"回文'是正读和反读都一样的字符串(不区分大小写字母)。
例如,LEVEL和Level是'回文",而LEVLEV不是"回文"。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int fun(char*s)
{ char*lp,*rp;
/*********found*********/
lp=
【1】
;
rp=s+strlen(s)-1;
while((toupper(*ip)==toupper
(*rp))&&(lp<rp)){
/*********found*********/
lp++;rp
【2】
;}
/*********found*********/
if(lp<rp)
【3】
;
else return 1;
}
main()
{char s[81];
printf("Enter a string:");
scanf("%s",s);
if(fun(s))
printf("\n\"%s\’is a Palindrome.\n\n”,s);
else
printf(“\n\"%s\"isn't a Palindrome.\n\n",s);
}
【正确答案】正确答案:(1)s (2)-- (3)retum 0
【答案解析】解析:填空1:根据函数体fun中,对变量lp和rp的使用可知,lp应指向形参s的起始地址,rp指向s的结尾地址,所以应填s。 填空2:rp是指向字符串的尾指针,当每做一次循环rp向前移动一个位置,所以应填:--。 填空3:当lp和rp相等时,表示字符串是回文并返回1,否则就返回0,所以应填return 0。