Thursday, 4 November 2021

C Program to find Palindrome using recursion

C Program to find Palindrome using recursion

 

Program:-

#include <stdio.h>

#include<conio.h>

#include <math.h>

int reverse(int num);

int isPalindrome(int num); 

int main()

{

int num;     

printf("Enter any number: ");

scanf("%d", &num);

if(isPalindrome(num) == 1)

{

printf("%d is palindrome number.\n", num);

}

Else

{

printf("%d is NOT palindrome number.\n", num);

}

return 0;

}

int isPalindrome(int num)

{

if(num == reverse(num))

{

return 1;

}     

 return 0;

}

int reverse(int num)

{

int digit;     

if(num==0)

return 0;

digit = (int)log10(num)     

return ((num%10 * pow(10, digit)) + reverse(num/10));

}



Output:

Enter any number: 1221
1221 is palindrome
number.

 

No comments:

Post a Comment

google-site-verification: google18ae80885fc3d876.html