Skip to content
DATA STRUCTURE
DATA STRUCTURE

Learn everything about Data structure

  • Algorithms
  • DSA
  • Array
  • Stack
  • Queue
  • Matrix
  • Programs
  • Programming
DATA STRUCTURE

Learn everything about Data structure

Check the Palindrome number program in c programming

YASH PAL, February 26, 2023May 28, 2024

In this tutorial, we are going to write a program in a c programming language that will get the string as input from the user and then check if the equation/string is a palindrome number or not.

#include<stdio.h>
#include<conio.h>
#define MAXSTK 10

struct stack
{
    int data[MAXSTK];
    int top;
};

int check( char []);
void push(struct stack *, int);
int pop(struct stack *);

void main()
{
    char str[10] = "";
    int flag=0;
    clrscr();
    printf("Enter a String:- ");
    gets(str);
    flag = check(str);

    if(flag == 1)
        printf("String is Palindrome.");
    else
        printf("String is not Palindrome.");
    getch();
}

int check(char str[])
{
    struct stack s1;
    int i = 0;
    s1.top = -1;

    while(str[i] != '\0')
        push(&s1, str[i++]);
    i=0;

    while(str[i] != '\0')
    {
        if(str[i] != pop(&s1))
            return(0);
        i++;
    }
    return(1);
}

void push(struct stack *p, int val)
{
    if(isfull(*p))
    {
        printf("Stack is Full.");
        return;
    }
    p->top++;
    p->data[p->top]=val;
}

int pop(struct stack *p)
{
    int val;
    if(isempty(*p))
    {
        printf("Stack is Empty.");
        return NULL;
    }
    val = p->data[p->top];
    p->top--;
    return(val);
}

int isfull(struct stack p)
{
    return(p.top == MAXSTK-1);
}

int isempty(struct stack p)
{
    return(p.top==-1);
}
data structures Programs stack DSAprogramsstack

Post navigation

Previous post
Next post
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • About US
  • Contact US
  • Data Structures and algorithms tutorials
  • Digital Communication Tutorials
  • DMCA
  • HackerRank All Algorithms problems solutions
  • HackerRank C problems solutions
  • HackerRank C++ problems solutions
  • HackerRank Java solutions
  • HackerRank Python solutions
  • Human Values Tutorials
  • Internet of Things Tutorials
  • Privacy Policy
©2025 DATA STRUCTURE | WordPress Theme by SuperbThemes