Source code:
/*A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, e.g. madam 123321 etc. Write a C code to check whether a given string is palindrome or not. */
#include <stdio.h>
#include <string.h>
int main(){
char string[20];
int flag = 0;
printf("Enter a string:");
//Read a String
scanf("%s", string);
int i, length;
length = strlen(string);
for(i=0; i < length ; i++){
if(string[i] != string[length-i-1]){
flag = 1;
break;
}
}
if (flag) {
printf("The given string %s is not palindrome", string);
}
else {
printf("The given string %s is palindrome", string);
}
return 0;
}
Output:
No comments:
Post a Comment