试题二(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]下面的程序按照以下规则输出给定名词的复数形式:a. 若名词以“y”结尾,则删除 y 并添加“ies” ;b. 若名词以“s” 、 “ch”或“sh”结尾,则添加“es” ;c. 其他所有情况,直接添加“s” 。[C 程序]#include stdio.h#include string.hchar *plural(char *word){int n;char *pstr;n = strlen(word); /*求给定单词的长度*/pstr = (char *)malloc(n+3); /*申请给定单词的复数形式存储空间*/if (!pstr || n 2)return NULL;strcpy(pstr,word); /*复制给定单词*/if ( (1) ){pstr[n-1] = 'i'; pstr[n] = 'e'; pstr[n+1] = 's'; (2) ;}elseif(pstr[n-1]=='s'||pstr[n-1]== 'h' ( (3) )){pstr[n] = 'e'; pstr[n+1] = 's'; pstr[n+2] = '\0';}else{ pstr[n] = 's'; pstr[n+1] = '\0'; }(4) ;}main( ){ int i; char *ps;char wc[9][10] ={"chair","dairy","boss","circus","fly","dog","church","clue","dish"}for(i = 0; i 9; i++) {ps = (5) ;printf("%s: %s\n",wc[i],ps); /*输出单词及其复数形式*/free(ps); /*释放空间*/}system("pause");}
试题二(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
[说明]
下面的程序按照以下规则输出给定名词的复数形式:
a. 若名词以“y”结尾,则删除 y 并添加“ies” ;
b. 若名词以“s” 、 “ch”或“sh”结尾,则添加“es” ;
c. 其他所有情况,直接添加“s” 。
[C 程序]
#include <stdio.h>
#include <string.h>
char *plural(char *word)
{
int n;
char *pstr;
n = strlen(word); /*求给定单词的长度*/
pstr = (char *)malloc(n+3); /*申请给定单词的复数形式存储空间*/
if (!pstr || n < 2)
return NULL;
strcpy(pstr,word); /*复制给定单词*/
if ( (1) )
{
pstr[n-1] = 'i'; pstr[n] = 'e'; pstr[n+1] = 's'; (2) ;
}
else
if(pstr[n-1]=='s'||pstr[n-1]== 'h' && ( (3) ))
{
pstr[n] = 'e'; pstr[n+1] = 's'; pstr[n+2] = '\0';
}
else
{ pstr[n] = 's'; pstr[n+1] = '\0'; }
(4) ;
}
main( )
{ int i; char *ps;
char wc[9][10] =
{"chair","dairy","boss","circus","fly","dog","church","clue","dish"}
for(i = 0; i < 9; i++) {
ps = (5) ;
printf("%s: %s\n",wc[i],ps); /*输出单词及其复数形式*/
free(ps); /*释放空间*/
}
system("pause");
}