Answer to Question #253161 in C++ for Hazzy

Question #253161

Exercise 1 : Practice to manipulate character arrays

A palindrome is a word, phrase, number or other sequence of characters which reads the same backward and forward.

Write a C program that enter a word, store it in an array and determine whether it is palindrome or not.

Example : CIVIC is a palindrome

HOT is a not a palindrome


1
Expert's answer
2021-10-18T15:06:46-0400
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
    char str[256];
    int n, i;
    int isPalindrome=1;

    scanf("%s", str);
    n = strlen(str);

    for (i=0; i<n/2; i++) {
        if (tolower(str[i]) != tolower(str[n-1-i])) {
            isPalindrome = 0;
            break;
        }
    }
    printf("Word \"%s\" %s a palindrome\n", str,
            isPalindrome ? "is" : "is not");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS