Mon May 28 2018
Palindrome String
C Programming1209 views
File Name: palindrome-string.c
/* Without using string function */
#include<stdio.h>
int main() {
int i, j = 0, k = 0;
/* Declaration of character type array */
char str[30];
printf("Check the given string is Palindrome or not\n");
printf("Enter any String upto 30 characters:\n");
/* Received string in a character array */
scanf("%29s", str);
/* "For loop" to count the length of the string */
for(i=0; str[i] != '\0'; i++);
for(j = i - 1; j >= 0 ; j--) {
/* Compare the string from left and right both side in a same array */
if(str[j] == str[k])
k++;
else
break;
}
if(i == k)
printf("String is Palindrome!\n");
else
printf("String is not Palindrome!\n");
return 0;
}
/* Output */
Check the given string is Palindrome or not
Enter a String:
asdsa
Sting is Palindrome!
/* ---------------------------------- */
Check the given string is Palindrome or not
Enter a String:
asdfg
Sting is not Palindrome!
Reference:
Palindrome string
Author:Geekboots