AD1

Tuesday, 7 March 2017

Palindrome String

Write a C code to check a String is palindrome or not , Some palindrome strings examples are "a", dad", "radar", "madam", "abcba" etc.

solution
#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;
}
view raw palin.c hosted with ❤ by GitHub



No comments:

Post a Comment