//Palindrome Number
A number that is equal to the reverse of that same number is called a palindrome number. For example, 3553, 12321, etc.
CODE
👇
- #include <stdio.h>
- int main()
- {
- int n,r,sum=0, temp;
- printf("Enter the number:");
- scanf("%d", &n);
- temp=n;
- while(n>0)
- {
- r=n%10;
- sum=(sum*10)+r;
- n=n/10;
- }
- if(temp==sum)
- printf(">>Palindrome Number<<\n");
- else
- printf(">>Not Palindrome<<\n");
- return 0;
- }
👉Execute👈
/*
Output
1]
Enter the number:5116532
>>Not Palindrome<<
2]
*/
//Palindrome String
Palindrome string if the reverse of that string is the same as the original string. For example, radar , level , etc.
Palindrome String(Main File)
CODE
👇
- #define false 0
- #define true 1
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "palindrome.h"
- char str[20];
- void main()
- {
- int i,l;
- STACK s;
- char str[20], ch;
- initstack();
- printf("Enter a string:");
- scanf("%s",str);
- l = strlen(str);
- printf("Length of string:%d",l);
- for(i=0; i<l; i++)
- {
- printf("\n push str=%c",str[i]);
- push(str[i]);
- }
- for(i=0; i<l; i++)
- {
- ch=pop();
- printf("\n pop ch=%c",ch);
- printf("\n str[%d]=%c",i,str[i]);
- if(ch!=str[i])
- {
- printf("\n>> '%s' IS NOT PALINDROME<<\n",str);
- exit(0);
- }
- }
- printf("\n>> '%s' IS PALINDROME<<\n",str);
- }
Palindrome String(Header File)
CODE
👇
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 10
- typedef struct
- {
- char data[MAX];
- int top;
- }STACK;
- STACK s;
- char ch;
- void initstack()
- {
- s.top = -1;
- }
- int isfull()
- {
- if(s.top == MAX-1)
- return 1;
- else
- return 0;
- }
- int isempty()
- {
- if(s.top == -1)
- return 1;
- else
- return 0;
- }
- void push(char ch)
- {
- if(isfull())
- printf(">>STACK IS FULL<<");
- else
- {
- printf("\tchar=%c",ch);
- s.top++;
- s.data[s.top]=ch;
- printf("\ttop=%d",s.top);
- }
- }
- char pop()
- {
- if(isempty())
- printf(">>STACK IS EMPTY<<");
- else
- {
- printf("\n\n pop top=%d",s.top);
- ch=s.data[s.top];
- s.top = s.top -1;
- return ch;
- }
- }
Output
/*
1]
Enter a string:madam
Length of string:5
push str=m char=m top=0
push str=a char=a top=1
push str=d char=d top=2
push str=a char=a top=3
push str=m char=m top=4
pop top=4
pop ch=m
str[0]=m
pop top=3
pop ch=a
str[1]=a
pop top=2
pop ch=d
str[2]=d
pop top=1
pop ch=a
str[3]=a
pop top=0
pop ch=m
str[4]=m
>> 'madam' IS PALINDROME<<
*/
//ThE ProFessoR
Comments
Post a Comment