Flames Program to find relationship

Flames Program to find relationship

Question:

Write a program to implement flames concept in any language.

Logic:

  • Get the two names from the user.
  • Eliminate the matching characters by comparing the names.
  • After elimination calculate the sum of the length of both names.
  • Then remove characters in FLAMES by applying conditions.
  • And then print the relation using the last character in FLAMES.

Algorithm:

  1. Get the two strings from the user.
  2. Add the length of the two names.
  3. Check the matching elements in two words and decrement length by two.
  4. Then eliminate characters in FLAMES by applying conditions.
  5. By using the last element in FLAMES print the relation.

Program:

void main()
{    
     char a[100],b[100],c[6]="FLAMES",g;
     int p,q,r,i,j,k,l,e,d=6,f;
     printf("Enter the first name:\n");
     gets(a);
     printf("Enter the second name:\n");
     gets(b);
     p=strlen(a);
     q=strlen(b);
     r=p+q;                      //add the length of two names
     f=d;
     printf("the flames between two is");
     for(i=0;i<p;i++)
     {
	 for(j=0;j<q;j++)
	 {
	     if(a[i]==b[j])      //checks the elements in two words if equal subtract two from r
	     {
		 r=r-2;
		 break;
	     }
	 }
     }
     for(k=0;k<f-1;k++)
     {
	 e=r%d;
	 if(e==0)
	 {
	      e=d-1;
	 }
	 else
	 {
	      e=e-1;
	 }
	 for(l=e;l<d;l++)        //delete the letters in FLAMES
	 {
	      c[l]=c[l+1];
         }
         d--;
     }
     g=c[0];                    //gets the last letter remains
     switch(g)                  //prints the relationship between two
     {
	 case 'F':
	       printf("friends");
	       break;
	 case 'L':
	       printf("love");
	       break;
	 case 'A':
	       printf("affection");
	       break;
	 case 'M':
	       printf("marriage");
	       break;
	 case 'E':
	       printf("enemy");
	       break;
	 case 'S':
	       printf("sister");
	       break;
	 default:
	       printf("nothing");
     }
     getch();
}

You might also like…

C Program To Play Flames Game | CodeChef | HackerRank

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Vignesh

A Computer Science graduate who likes to make things simpler. When he’s not working, you can find him surfing the web, learning facts, tricks and life hacks. He also enjoys movies in his leisure time.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x