Programme For Palindrome
Hi,
I want how to write Palindrome programme programme without using any string functions and without any loops like while,do while.
Any one can tell simple way.
Thanks In advance,
MOULALI.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Brajesh KumarRank #678 · 3.5K reputationPosted Feb 24, 2017, 7:13 AM EST
palindrome Program using recursion
int checkPalindrome(int);
int main(){
int num,sum;
printf("Enter a number: ");
scanf("%d",&num);
sum = checkPalindrome(num);
if(num==sum)
printf("%d is a palindrome",num);
else
printf("%d is not a palindrome",num);
return 0;
}
int checkPalindrome(int num){
static int sum=0,r;
if(num!=0){
r=num%10;
sum=sum*10+r;
checkPalindrome(num/10);
}
return sum;
#include
int is_palindrome(char*);
void copy_string(char*, char*);
void reverse_string(char*);
int string_length(char*);
int compare_string(char*, char*);
int main() {
char string[100];
int result;
printf("Enter a string\n");
gets(string);
result = is_palindrome(string);
if ( result == 1 )
printf("\"%s\" is a palindrome string.\n", string); else
printf("\"%s\" is not a palindrome string.\n", string);
return 0;
}
int is_palindrome(char *string) {
int check, length;
char *reverse;
length = string_length(string);
reverse = (char*)malloc(length+1);
copy_string(reverse, string);
reverse_string(reverse);
check = compare_string(string, reverse);
free(reverse);
if ( check == 0 )
return 1; else
return 0;
}
int string_length(char *string) {
int length = 0;
while(*string) {
length++;
string++;
}
return length;
}
void copy_string(char *target, char *source) {
while(*source) {
*target = *source;
source++;
target++;
}
*target = '\0';
}
void reverse_string(char *string) {
int length, c;
char *begin, *end, temp;
length = string_length(string);
begin = string;
end = string;
for ( c = 0 ; c < ( length - 1 ) ; c++ )
end++;
for ( c = 0 ; c < length/2 ; c++ ) {
temp = *end;
*end = *begin;
*begin = temp;
begin++;
end--;
}
}
int compare_string(char *first, char *second) {
while(*first==*second) {
if ( *first == '\0' || *second == '\0' )
break;
first++;
second++;
}
if( *first == '\0' && *second == '\0' )
return 0; else
return -1;
}