Palindrome Using Stack in C

Description

This program is used to check whether given input is PALINDROME or not using Stack.

#include<stdio.h>
#include<string.h>
#define MAX 100
void input();
char stack[MAX];
int top= -1;
void push(char x)
{
 stack[++top]=x;
}

char pop()
{
 if(top==-1)
 return -1;
 else
 return stack[top--];
}

main()
{
 int choice;
 do
 { 
  printf("\n\n---MENU---\n1.INPUT\n2.EXIT\n");
  printf("\nEnter your Choice\n");
  scanf("%d",&choice);
  switch(choice)
  {
   case 1 : input();break;
   case 2 : printf("~~~~~~~THANK YOU~~~~~~~\n");break;
   default : printf("\nINVALID INPUT !!!!\n");break;
  }
 }while(choice!=2);
}

void input()
{ 
 top=-1;
 int i = 0; 
 char exp[100];
 printf("Enter a string :  ");
 scanf("%s",&exp);
 while(exp[i]!='\0')
 {
  push(exp[i++]);
 }
 i=0;
 while(exp[i++]==pop());
 if(top==-1)
 printf("\nIt is a palindrome...");
 else printf("\nIt is not palindrome !!!");
}


OUTPUT

Palindrome Output

Labels: