C PROGRAMMING Create a program that is asking the user for an input that\'s noun
ID: 640683 • Letter: C
Question
C PROGRAMMING
Create a program that is asking the user for an input that's noun and than prints out its plural form.
The following rules below will be used for making nouns plural.
Ends Plural Form
ch, sh, s, x, or z
Add es
vowel and y
Add s
a consonant and y
Y becomes ies
f or fe
Becomes ves
All others
Add s
-The case of each character should be preserved
-You may only use %s format specifier to display your string
-The user will only enter alphabetical characters
-No words wil be bigger than 10 characters
* Don't forget to be restoring the null character at the end of the string
Examples
Please enter a word: boy
The plural from of boy is boys.
Please enter a word: loaf
The plural from of loaf is loaves.
Please enter a word: moose
The plural from of moose is mooses.
ch, sh, s, x, or z
Add es
vowel and y
Add s
a consonant and y
Y becomes ies
f or fe
Becomes ves
All others
Add s
Explanation / Answer
#include #include #define max_word 20 /* prototypes */ void pluralize (char word[]); int main (void) { char noun[max_word]; /* stores temporary word entered by user */ printf("Enter a noun in singular form: "); scanf("%s", noun); while (strcmp(noun, "done") != 0) { pluralize (noun); printf("The plural form is %s ", noun); } return; } void pluralize (char word[]) { int length; char noun; length=1; length = strlen(word); if (word[length - 1] == 'y') { word[length - 1] = 'i'; word[length] = 'e'; word[length + 1] = 's'; word[length + 2] = ''; } /* if word ends in "s" "ch" or "sh" add "es" */ else if (word[length - 1] == 's' || (word[length - 2] == 'c' && word[length - 1] == 'h') || (word[length - 2] == 's' && word[length - 1] == 'h')) { strcat(word, "es"); } else { strcat(word, "s"); printf("New word is: ", &noun); } return; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.