Write a C code to check a String is palindrome or not , Some palindrome strings examples are "a", dad", "radar", "madam", "abcba" etc.
solution
This file contains 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
#include <stdio.h> | |
#include <string.h> | |
int main() | |
{ | |
// a program to check a string is palindrome or not | |
char string[20]; | |
printf("Enter the string\n"); | |
gets(string); | |
unsigned int i=0; | |
unsigned int j=strlen(string)-1; | |
unsigned int flag=0; | |
while(i!=j) | |
{ | |
if(string[i]==string[j]){i++,j--;continue;} | |
else {flag=1;break;} | |
} | |
if(flag==0){printf("string is palindrome\n");} | |
else if(flag==1){printf("string is not palindrome\n");} | |
return 0; | |
} |
No comments:
Post a Comment