Monday, 5 October 2015

Find given string is palindrome or not using string library function.

  
   
#include<stdio.h>
#include<string.h>
void main() {
    char string[25], reverse_string[25] = {'\0'};
    int i, length = 0, flag = 0;
    printf("Enter a string \n");
    gets(string);
    length = strlen(string);
    printf("The length of the string '%s' = %d\n", string, length);
    for (i = length - 1; i >= 0; i--) {
        reverse_string[length - i - 1] = string[i];
    }
    for (i = 0; i < length; i++) {
        if (reverse_string[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);
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.

No comments:

Post a Comment