Sunday, August 24, 2014

String palindrome

Write a program to to calculate string palindrome.

SOLUTION:

 /*
 * Title: String palindrome
 * Written by Shaeed Khan. 
 * Date: 24 Aug 2014
 * Version- 1.0 
 * Language: C
 */

#include < stdio.h >      
#include < stdlib.h > 

void main()
{
	char x[100],y[100];
	printf("Enter a string :");
	scanf("%s",x);
	strcpy(y,x);
	check_palindrome(x);
	if(strcmp(x,y)==0)
		printf("Palindrome");
	else
		printf("Not Palindrome");
}

int check_palindrome(char *x)
{
	int len=strlen(x);
	int i;
	char temp;
	for( i = 0; i < len / 2; i++)
	{
		temp = x[i];
		x[i]  =x[len-i-1];
		x[len-i-1] = temp;
	}
} 

No comments:

Post a Comment