Created
November 22, 2017 01:45
-
-
Save alexnum/060f17d0c7124a9b6a74b4f15f72a3a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
Online C Compiler. | |
Code, Compile, Run and Debug C program online. | |
Write your code in this editor and press "Run" button to compile and execute it. | |
*******************************************************************************/ | |
#include <stdio.h> | |
int main() | |
{ | |
char string[25], reverseString[25] = {'\0'}; | |
int i, length = 0, flag = 0; | |
fflush(stdin); | |
printf("Enter a word \n"); | |
gets(string); | |
for(int i = 0; string[i] != '\0'; i++){ | |
string[i] = tolower(string[i]); | |
} | |
/* keep going through each character of the string till its end */ | |
for (i = 0; string[i] != '\0'; i++) | |
{ | |
length++; | |
} | |
for (i = length - 1; i >= 0; i--) | |
{ | |
reverseString[length - i - 1] = string[i]; | |
} | |
/* | |
* Compare the input string and its reverse. If both are equal | |
* then the input string is palindrome. | |
*/ | |
for (i = 0; i < length; i++) | |
{ | |
if (reverseString[i] == string[i]) | |
flag = 1; | |
else | |
flag = 0; | |
} | |
if (flag == 1) | |
printf("%s is a palindrome \n", string); | |
else | |
printf("%s is not a palindrome \n", string); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment