Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include<string.h>
- #define MAX 100
- char stack[MAX];
- int top=-1;
- void push(char s);
- void pop();
- int main()
- { char s[100];
- int front=0,flag=0;
- printf("Enter the string\n");
- gets(s);
- for(int i=0;i<strlen(s);i++)
- push(s[i]);
- printf("Reverse of the string is \n");
- pop();
- for(int i=0;i<(strlen(s)/2);i++)
- {
- if(stack[front]==' ')
- front++;
- if(stack[top]==' ')
- top--;
- if(stack[front]!=stack[top])
- {flag=1;
- break;
- }front++;
- top--;
- }
- if(flag==0)
- {
- printf("\nstring is a palindrome");
- }
- else
- printf("\nstring is not a palindrome");
- return 0;
- }
- void push(char s)
- {
- top++;
- stack[top]=s;
- return;
- }
- void pop()
- {int t=top;
- for(int i=t;i>-1;i--)
- printf("%c",stack[i]);
- return;
- }
Add Comment
Please, Sign In to add comment