Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Palindrome Stack Integer.c #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions stack/Palindrome Stack Integer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//code

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define SIZE 100

struct stack
{
int data[SIZE];
int top;
};
void push(struct stack *sptr, int num);
void check(struct stack *sptr,int no);
int pop(struct stack *sptr);

void push(struct stack *sptr, int num)
{
if(sptr->top==SIZE-1)
{
printf("Stack Overflow\n");
}
else
{
sptr->top++;
sptr->data[sptr->top]=num;
}
}
int pop(struct stack *sptr)
{
int num;
num=sptr->data[sptr->top];
sptr->top--;
return num;
}

void check(struct stack *sptr,int no)
{
int temp,num=no,copy,c=0,stat=1;
while(no!=0)
{
temp=no%10;
push(sptr,temp);
c++;
no=no/10;
}
copy=num;
while(copy!=0)
{
temp=copy%10;
if(temp!=pop(sptr))
{
stat=0;
break;
}
copy=copy/10;
}
if(stat==1)
{
printf("%d is a palindrome number",num);
}
else
{
printf("%d is not a palindrome number",num);
}


}
int main()
{
struct stack * sptr;
struct stack s;
int no;
sptr=&s;
sptr->top=-1;
scanf("%d",&no);
if(no>0)
{
check(sptr,no);
}
else
{
printf("Invalid number ");
exit(0);
}
return 0;
}


/*Execution

121

Your Output (stdout)
121 is a palindrome number