AIM
To write a C program to find
whether the string is palindrome or not.
ALGORITHM:
Step-1: Start the program
Step-2: Enter the string
Step-3: Find the string
length using the strlen() function
Step-4: Print the string
length
Step-5: Set a loop up to the
half of the string length
Step-6: Compare every
character above the middle character with the below character
of the middle character
Step-7: If any character
equal prints the given string is palindrome
Step-8: If the character is
not equal then print the given string is not a palindrome
Step-9: Stop
PROGRAM
#include<stdio.h>
#include<stdlib.h>
void main()
{
int len=0,i,j;
char name[25];
printf(“Enter
the string...”);
scanf(“%s”,name);
while(name[len]!=’\0')
len++;
printf(“\n%d”,len);
for(i=0,j=len-1;i<len/2;i++,j-)
{
if(name[i]!=name[j])
{
printf(“\nThe given string is not a palindrome”);
exit(0);
} }}
OUTPUT
Enter the string...engineering
11
The given string is not a palindrome
RESULT: Thus a c
program to check the given string for palindrome is executed.
No comments:
Post a Comment