Palindrome Missing Alphabet

Palindrome Missing Alphabet 

String S which is a palindrome is passed as the input. But just one alphabet is missing in S.The program must print the missing alphabet A.
Note: The first alphabet of S will always be present.
Sample Input 1:
malayaam
Sample Output 1:
malayalam
missing character : l

Sample Input 2 :
abcddcb
Sample Output 2:
abcddcba
missing character : a

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
 char str[20],temp[20],cha;
 int count=0,i,j,len;
 clrscr();
 printf("enter the string : ");
 gets(str);
 strcpy(temp,str);
 strrev(temp);
 len=strlen(str);
 for(i=0;i<=len;i++)
 {
  if(str[i]==temp[i])    //if same elt is present in both the array
  {
  printf("%c",temp[i]);
  }
  else if(count>0)    //after insert the missing character 
  {              //print remaining character without going to else loop
  printf("%c",temp[i]);
  }
  else          //insert missing character
  {
   for(j=len-1;j>=i;j--)
   {
   temp[j+1]=temp[j];//before insert shift the character one pos right
   }
   temp[i]=str[i];      //insert character
   cha=temp[i];
   printf("%c",temp[i]);
   count=count+1;
  }
 }
 printf("\nmissing character : %c",cha);
 getch();
 return 0;
}

OUTPUT




0 comments