If you have younger brothers or sisters, they may have watched Phineas and Ferb
ID: 3781289 • Letter: I
Question
If you have younger brothers or sisters, they may have watched Phineas and Ferb on the Disney Channel. In one episode, Phineas and Ferb decide to create their own language, Ferb Latin. Write a program that translates a first name and a last name stored in string variables called first and last to to Ferb Latin using the following rules: If the length of the name is less than three letters, the name is not changed. If the length of the name is three or more letters, move the first letter to the end and add "erb" Output the new name to the screen. The first letter of both the first and last name should be capitalized. All other letters should be lowercase. Think about how you can use the substring, toLowerCase, and toUpperCase methods to create the new strings. Here are two examples: first = "Justin"; last = "Bieber"; Your name in Ferb Latin is Ustinjerb leberberb first = "Ed"; last = "Sullivan"; Your name in Ferb Latin is Ed Ullivanserb Test your program with several different names to make sure it works.Explanation / Answer
#include <stdio.h>
#include<string.h>
int a,b,i;
char first[30],last[30] ,temp1[30],temp2[30];
char m[3]="erb";
int main ()
{
char x[1],y[1];
printf("enter first name: ");
gets (first);
printf("enter last name : ");
gets("last");
a=strlen(first);
b=strlen(last);
if (a<3)
{
strcpy(temp1,first);
}
else
{
// for first name
x[0]=first[0];
for (i=1;i<=a;i++);
{
temp1[i-1]=first[i];
}
temp1[a]=x[0];
strcat(temp1, m);
}
// for last name
if (b<3)
{
strcpy(temp2,last);
}
else
{
y[0]=last[0];
for (i=1;i<=b;i++);
{
temp2[i-1]=last[i];
}
temp2[b]=y[0];
strcat(temp2, m);
}
printf ("%s %s" ,temp1,temp2);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.