Whole India is tweeting about the probable names for Aishwarya Rai's daughter. Some astrologers are suggesting that she will grow up to be a more famous celebrity than Aishwarya if her name is a palindrome. As we all know, a palindrome is a word that can be read the same way in either direction.
Write a C program to determine whether a given word is a palindrome or not. Do not use any string library functions.
Input Format:
Input consists of a single string. Assume that the maximum length of the string is 50.
Sample Input:
Enter the word
hannah
Sample Output:
hannah is a palindrome

Sample Input:
Enter the word
bina
Sample Output:
bina is not a palindrome

Program Code:
#include<stdio.h>
int main()
{
    char str1[50];
    //string str1,str2;
    int length=0;int flag=0; int i=0;
    printf("Enter the word");
    scanf("%s",str1);
    while(str1[i]!='\0')
{
        length++;
        i++;
}
    for(i=0;i<length ;i++)
{
        if(str1[i] != str1[length-i-1])
{
            flag = 1;
            break;
}
}
    if(flag==0)
    printf("\n%s is a palindrome",str1);
    else
    printf("\n%s is not a palindrome",str1);
     return 0;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: