Answer to Question #183075 in C for jhon

Question #183075

Write a program using string function that determines if the input word is a

palindrome. A palindrome is a word that produces the same word when it is

reversed.

Enter a word: AHA

Reversed word: AHA

It is a palindrome.


1
Expert's answer
2021-04-19T03:54:58-0400
#include <stdio.h>
#include <string.h>


int isPalindrome(char inputString[]);


int main()
{
	
    char inputString[40];
    //get a string from the user
	printf("Enter a string: ");
    scanf("%s",inputString);
	//display result
	if(isPalindrome(inputString)==1){
         printf("The word %s is a palindrome", inputString);		
	}else{
		printf("The word %s is NOT a palindrome", inputString);		
	}


	getchar();
	getchar();
    return 0;
}


//Checks if word is a palindrome
int isPalindrome(char inputString[]){
    int index = 0;
    int length = strlen(inputString) - 1;
    while (length > index)
    {
        if (inputString[index] != inputString[length])
        {
            return 0;
        }
		index++;
		length--;
    }
	return 1;
}

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