C语言题目一个,求高手帮忙,用VC6.0编写,要编译通过再贴上来,谢谢了。

2025-03-02 14:59:28
推荐回答(4个)
回答1:

/*
请输入一个名词 : print
复数形式是 : prints
0:继续,其他:结束 :0
请输入一个名词 : tomato
复数形式是 : tomatoes
0:继续,其他:结束 :0
请输入一个名词 : bench
复数形式是 : benches
0:继续,其他:结束 :0
请输入一个名词 : lady
复数形式是 : ladies
0:继续,其他:结束 :1
请按任意键继续. . .
*/
#include
#include

char *PluralNoun(char *word) {
int len = strlen(word);
if(word[len - 1] == 'y') {
word[len - 1] = '\0';
strcat(word,"ies");
}
else if(word[len - 1] == 'o' || word[len - 1] == 's' || word[len - 1] == 'x')
strcat(word,"es");
else if(word[len - 1] == 'h' && (word[len - 2] == 'c' || word[len - 2] == 's'))
strcat(word,"es");
else strcat(word,"s");
return word;
}

int main() {
char word[36];
int an;
do {
printf("请输入一个名词 : ");
gets(word);
PluralNoun(word);
printf("复数形式是 : %s\n",word);
printf("0:继续,其他:结束 :");
scanf("%d",&an);
fflush(stdin);
}while(an == 0);
return 0;
}

回答2:

//编译运行没有问题
#include
void change(char *p)
{
while(*p){
if(*(p+1) < 'a' || *(p+1) >'z')
break;
p++;
}
switch(*p){
case 'y': *p = 'i';*++p= 'e';break;
case 's':
case 'x':
case 'o': *++p = 'e';break;
case 'h':
if(*(p-1) =='c' ||*(p-1) =='s' )
*++p = 'e';break;
default:break;
}
*++p = 's';
*++p = '\0';
}

int main()
{
char word[20];
printf("input a word.\n");
scanf("%s",word);
change(word);
printf("now,the plural is %s\n",word);
}

回答3:

#include
#include

int main()
{
char word[256];
int pos = 0;

while (1)
{
scanf("%s", word);
pos = strlen(word);
if (word[pos-1] == 'y')
{
word[pos-1] = '\0';
strcat(word, "ies");
}
else if ((word[pos-1] == 's')||(word[pos-1]=='x')
|| ((word[pos-2] == 'c')&&(word[pos-1] == 'h'))
|| ((word[pos-2] == 's')&&(word[pos-1] == 'h')))
{
strcat(word, "es");
}
else if(word[pos-1] == 'o')
{
strcat(word,"es");
}
else
{
strcat(word, "s");
}
printf("%s\n", word);
}
return 0;
}

回答4:

#include
#include
#define N 20
void main(){
char str[N];
int len;
scanf("%s",str);
len=strlen(str);
if(str[len-1]=='y'){
str[len-1]='i';str[len]='e';str[len+1]='s';str[len+2]='\0';
}
else if(str[len-1]=='s'||str[len-1]=='x'||str[len-2]=='c'&&str[len-1]=='h'||str[len-2]=='s'&&str[len-1]=='h'||str[len-1]=='o'){
str[len]='e';str[len+1]='s';str[len+2]='\0';
}
else{
str[len]='s';str[len+1]='\0';
}
printf("%s\n",str);
}
该题有一点不够完备 原音O 无法根据它前面的字母确定