编写一个函数RegularPlural,其功能是实现一个英文单词的复数形式。复数的规则为:
(1) 如果单词末尾为s,x,z,ch或sh,则在后面加es
(2) 如果单词末尾为y,且前一个字母为辅音(除a, e, i, o, u以外的其它情况),则把y改成ies。
(3) 如果是其它情形,一律在后面加s。
编写测试程序,输入一个长度小于20的单词,输出该单词的复数形式。
输入:
box
输出:
boxes
(用C语言解决)

用C语言编写英文单词变复数形式的程序
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- a5156520 2021-12-30 17:07关注
一个实现:
#include <stdio.h> #include <string.h> void RegularPlural(char * str){ int lens = strlen(str); char ch = str[lens-1]; char pch = str[lens-2]; //第一种情况 if((ch=='s')||(ch=='x')||(ch=='z') ||(ch=='h'&&pch=='c')||(ch=='h'&&pch=='s')){ str[lens]='e'; str[lens+1]='s'; str[lens+2]='\0'; }else if((ch=='y')&&(pch!='a'&&pch!='e'&&pch!='i'&&pch!='o'&&pch!='u')){ //第二种情况 str[lens-1]='i'; str[lens]='e'; str[lens+1]='s'; str[lens+2]='\0'; } else { //其他 str[lens] = 's'; str[lens+1]='\0'; } } int main(void){ char word[30]; //循环测试代码 while(1){ gets(word); RegularPlural(word); printf("%s\n",word); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用