A Palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction.
for example
pop
deed
kayak
civic
radar
level
deified
rotator
repaper
testset
racecar
redivider
detartrated
malayalam
Code:
for example
pop
deed
kayak
civic
radar
level
deified
rotator
repaper
testset
racecar
redivider
detartrated
malayalam
Code:
//Program for palindrome
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[20];
int i,j,l;
clrscr();
printf("Enter name\n\n");
gets(s);
l=strlen(s);
for (i=0,j=l-1;i<j;i++,j--)
{
if (s[i]!=s[j])
{
printf("\nNot a Palindrome");
break;
}
else
printf("\nPalindrome");
}
getch();
}
Give comments if you have any doubts… :)#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[20];
int i,j,l;
clrscr();
printf("Enter name\n\n");
gets(s);
l=strlen(s);
for (i=0,j=l-1;i<j;i++,j--)
{
if (s[i]!=s[j])
{
printf("\nNot a Palindrome");
break;
}
else
printf("\nPalindrome");
}
getch();
}
Categories:
c program
3 comments:
hi there
the program doesn't give the correct solution for all data input, it checks for the first and last character same or not , if it is same it displays as palindrome without checking the other characters,
yes we will fix the code soon n will update.. thanks.. keep visiting.. :)
#include
#include
#include
void main()
{
char s[20];
int i, j, l, count = 0;
printf("Enter name\n");
gets(s);
l = strlen(s);
for (i=0,j=l-1;i<j;i++,j--)
if (s[i]==s[j])
count++;
if(l/2 == count)
printf("\nPalindrome\n");
else
printf("\nNot a Palindrome\n");
getch();
}
Post a Comment