Check palindrome without using library functions

Check palindrome without using library functions

write a C program to check the string whether it is palindrome or not 
CONSTRAINT : without using library functions

Sample input   1: madam
Sample output 1: Palindrome

Sample input  2  : jobat
Sample output 2 : Not a Palindrome

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <string.h>
int main() {
    char str[30];
    int len,start,end,flag=0;
    gets(str);
    //length of string
    for(int i=0;str[i];len++,i++);
    //check palindrome with two pointers for start and end
    for( start=0,end=len-1;start<end;start++,end--)
    {
        if(str[start]!=str[end])
        {
            flag=1;
            break;
        }
    }
     if(flag==0)
         printf("Palindrome");
    else
        printf("Not a Palindrome");
    return 0;
}

OUTPUT :

2 comments