Question 3 You can turn a word into pigLatin using the following two rules (simp
ID: 3716177 • Letter: Q
Question
Question 3 You can turn a word into pigLatin using the following two rules (simplified): If the word starts with a consonant, move that letter to the end and append 'ay' . For example, 'happy' becomes 'appyhay' and 'pencil' becomes 'encilpay' . If the word starts with a vowel, simply append 'way' to the end of the word. For example, 'enter' becomes 'enterway' and 'other' becomes 'otherway For our purposes, there are 5 vowels: a, e, i, o, u (so we count y as a consonant). Write a function pig) that takes a string as input and returns pigLatin form of its content. Your function should still work if the input string contains upper case characters. Your output should always be lower case however The following shows the behavior of the function for some sample parameters. >>>pig('test') 'esttay' >>>pig('east') 'eastway' >>> pig('EAST') 'eastway >>>pig('meal') ealmay'Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define length 1000
void pig(char s[]){
int i;int j;char t[3]="way";int k=0;char p[2]="ay";
if(s[0]=='a'||s[0]=='e'||s[0]=='i'||s[0]=='o'||s[0]=='u'|| s[0]=='A'||s[0]=='E'||s[0]=='I'||s[0]=='O'||s[0]=='U') //Checks whether the particular character is a vowel
{
for(j=strlen(s);j<strlen(s)+3;j++) //Now since we found the starting letter as vowel,just append 'way' at ending
s[j]=t[k++];
s[j]='';
printf("%s",s);
}
else //If the starting Character is a Consonant just apply following
{
for(j=strlen(s)+1;j<strlen(s)+3;j++)
s[j]=p[k++]; // append "ay" at the end;
s[strlen(s)]=s[0]; // place the stating character at end of the string
s[j]='';
printf("%s",s+1);
}
}
int main(){
char str[length];
scanf("%s",str);
pig(str);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.