C Program – Find the total number of palindrome in a given string

by Nideesh C on April 18, 2011 · 0 comments

in C Programming




#include<stdio.h>
#include<conio.h>
int stpal(char str[50], int st, int ed);
void main()
{
char str[50];
int pal = 0, len = 0, i, start = 0, end;
clrscr();
printf(“nnt ENTER A SENTENCE…: “);
gets(str);
while(str[len]!=’′)
len++;
len–;
for(i=0;i<=len;i++)
{
if((str[i] == ‘ ‘ && str[i+1] != ‘ ‘) || i == len)
{
if(i == len)
end = i;
else
end = i – 1;
if( stpal (str, start, end ) )
pal++;
start = end + 2;
}
}
printf(“nnt THE TOTAL NUMBER OF PALINDROMES ARE..: %d”,pal);
getch();
}
int stpal(char str[50], int st, int ed)
{
int i, pal=0;
for(i=0; i<=(ed-st)/2; i++)
{
if(str[st+i] == str[ed-i])
pal = 1;
else
{
pal = 0;
break;
}
}
return pal;
}

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program – To check whether the given string is palindrome
  2. C Program – To replace a word by another word in a given string
  3. C program to accept a string and find the number of times the word ‘the’ appears in it
  4. C program – Copy the contents of one string to another string using pointer
  5. C program – To copy the contents of one string to another string

Leave a Comment

Previous post:

Next post: