USE C PROGRAMMING LANGUAGE. You will need to write a program that reads an input
ID: 3754251 • Letter: U
Question
USE C PROGRAMMING LANGUAGE.
You will need to write a program that reads an input string representing a sentence, and convert it into pig latin. We'll be using two simple rules of pig latin: 1.If the word begins with a consonant then take all the letters up until the first vowel and put them at the end and then add "ay" at the end. 2. If the word begins with a vowel then simply add "yay" to the end. For this problem vowels are defined as: a, e, i, o, and u. There will only be characters in your input (no numbers or punctuation) Input-Output format: This program takes a string of space-separated words and should output the same space-separated words translated into pig latin. Example 1: $./sixth Hello and welcome to computer architecture elloHay andyay elcomeway otay omputercay architectureyay Example 2: $./sixth a program ayay ogramprayExplanation / Answer
#include<stdio.h>//for input and output
#include<string.h>//for strings
#include<stdlib.h>//for dynamic allocation
int main()
{
char input[1000],output[100];//input[] array to store input and output array to store output
printf("enter only characters");
gets(input);//getting input from user
int i=0,j=0;
int k=i,p=0;
while((input[k])!=''){
if(k==0)
i=k;
else
i=k+1;
//the following if block for vowels
if(input[i]=='a' || input[i]=='e' || input[i]=='i' || input[i]=='o' || input[i]=='u' || input[i]=='u' || input[i]=='A' || input[i]=='E' ||
input[i]=='I' || input[i]=='O' || input[i]=='U')
{
while(input[i]!=' ' && input[i]!=''){
output[j]=input[i];
j++;
i++;
}
k=i;
output[j]='y';
j++;
output[j]='a';
j++;
output[j]='y';
j++;
if (input[k]==' '){
output[j]=' ';
j++;
}
}
//the following else block is for consonants
else
{
char *a;
int n=0;
a=(char*)malloc(5*sizeof(char));
while(p!=1){
if(input[i]=='a' || input[i]=='e' || input[i]=='i' || input[i]=='o' || input[i]=='u' || input[i]=='u' || input[i]=='A' || input[i]=='E' ||
input[i]=='I' || input[i]=='O' || input[i]=='U'){
a[n]='';
n++;
p=1;
}
else{
a[n]=input[i];
n++;
i++;
p=0;
}
}
p=0;
while(input[i]!=' ' && input[i]!='')
{
output[j]=input[i];
j++;
i++;
}
int h=0;
for(h=0;a[h]!='';h++){
output[j]=a[h];
j++;
}
k=i;
output[j]='a';
j++;
output[j]='y';
j++;
if (input[k]==' '){
output[j]=' ';
j++;
}
}
}
int d=0;
for(d=0;d<j;d++)
printf("%c",output[d]);//to display the output
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.