编写一个函数RegularPlural,其功能是实现一个英文单词的复数形式。复数的规则为:
(1) 如果单词末尾为s,x,z,ch或sh,则在后面加es
(2) 如果单词末尾为y,且前一个字母为辅音(除a, e, i, o, u以外的其它情况),则把y改成ies。
(3) 如果是其它情形,一律在后面加s。
编写测试程序,输入一个长度小于20的单词,输出该单词的复数形式。
输入:
box
输出:
boxes
(用C语言解决)
![](https://profile-avatar.csdnimg.cn/default.jpg!4)
用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无用
悬赏问题
- ¥15 宇视监控服务器无法登录
- ¥15 PADS Logic 原理图
- ¥15 PADS Logic 图标
- ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
- ¥15 DruidDataSource一直closing
- ¥20 气象站点数据求取中~
- ¥15 如何获取APP内弹出的网址链接
- ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
- ¥50 STM32单片机传感器读取错误
- ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据