Navigation Bar

Programe to Check Palindrome using recursion

#include<iostream>
using namespace std;
int palindrome(int num);

int main() {
   int num,number, val;
   cout<<"Enter a number: ";
   cin>>num;
   number=num; //save orignal number
   val = palindrome(num); //function call
   if(val==number) c//check returned value with orignal value/number
    cout<<"Number is Palindrome";
    else
     cout<<"Number is not Palindrome";
   return 0;
}
int palindrome(int num)
 {
     int rem;
     static int temp=0;
   if (num != 0)
   {
      rem =num%10;
      temp=(temp*10)+rem;
      palindrome(num/10); // recursive function call
   }
   return temp;
}

No comments:

Post a Comment