Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a script that will take 10 Last names and First names separately, then co

ID: 2249704 • Letter: C

Question

Create a script that will take 10 Last names and First names separately, then combine Last names and First names together, then display the full name in reverse order (Z to A). If same name occurs add Number # at the end of the name based on the repetition.

Ex.)

What is person 1’s last name? Griffin

What is person 1’s first name? Peter

What is person 2’s last name? Griffin

What is person 2’s first name? Stewie

What is person 3’s last name? Griffin

What is person 3’s first name? Chris

What is person 4’s last name? Griffin

What is person 4’s first name? Lois

What is person 5’s last name? Griffin

What is person 5’s first name? Brian

Output

Brian Griffin

Chris Griffin

Lois Griffin

Peter Griffin

Stewie Griffin

USE "C" LANGUAGE ONLY

Explanation / Answer

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define len 15//length of the either first or last name.One can change the value if required.
#define num 10//number of personsi
void main()
{
char f_name[num][50];//first name and subsequently represent full name
char l_name[num][len]; //last name
static int arr[9];
char join[2]=" ";
char seq[2];
char seq1[4];
int counter;
int i;
int j;
for(i=0;i<num;i++)
{
printf("What is person %d's last name? ",i+1) ;
gets(l_name[i]);
printf("What is person %d's first name? ",i+1) ;
gets(f_name[i]);
strcat(f_name[i],join);
strcat(f_name[i],l_name[i]);
}

for(i=1;i<num;i++)
{
counter=0;
for(j=0;j<i;j++)
{
if(!strcmp(f_name[i],f_name[j]))
counter++;
}
arr[i-1]=counter+1;
}
printf(" Dispalying names in reverse order ");
for(i=0;i<num;i++)
printf("%s ",strrev(f_name[i]));
for(i=0;i<num;i++)
strrev(f_name[i]);
printf("------------------------- ");
for(i=1;i<num;i++)
{

char seq1[4]="#";
if(arr[i-1]>1)
{
itoa(arr[i-1],seq,10) ;
strcat(seq1,seq);
strcat(f_name[i],seq1);
}
}
for(i=0;i<num;i++)
printf("%s ",f_name[i]);
printf(" -------------------------- ");
printf(" Dispalying names in reverse order ");
for(i=0;i<num;i++)
printf("%s ",strrev(f_name[i]));
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote