Sunday, 20 March 2016

C Program For Check String Is Palindrome Or Not

#include <stdio.h>
#include <string.h>

int main()
{
//Ghanendra Yadav
    char string1[20];
    int i, length;
    int flag = 0;
 
    printf("\nEnter a string:\n");
    scanf("%s", string1);
 
    length = strlen(string1);
 
    for(i=0;i < length ;i++)
{
        if(string1[i] != string1[length-i-1])
{
            flag = 1;
            break;
  }
}
 
    if (flag)
{
        printf("%s is not a palindrome\n", string1);
    }  
    else {
        printf("%s is a palindrome\n", string1);
    }
    return 0;
}

Output:-


No comments:
Write comments

Recommended Posts × +