Write a program to check if the number is palindrome or not using recursive function.

Showing Answers 1 - 2 of 2 Answers

baseersd

  • Jul 24th, 2007
 

Here is the code for palindrome with recursive mechanism

#include<stdio.h>

int rev=0; //Global Variable

int REV(int num)
{
if(num>0)
{
 rev=(rev*10)+ (num %10);
 REV(num / 10); //calling the Function recursively.        
}
return rev;       
}

int main()
{
int num;
printf("nEnter a number ");
scanf("%d",&num);
if(num==REV(num))
printf("nNumber is a Palindrome");
else
printf("nNot a palindrome");
getch();   
}

main
{ int sum = 0,n,n1,r;
 

 printf(" enter the number to be tested for palimdromen" );
  scan("%d",&n);
   n1=n;
   while(r!=0)
   {r=n%10;
     n=n/10;
      sum = sum*10+r;
   }
  if(sum==n1){
  printf(" the number is palimdromen ");
  }
  else
      { printf(" the number is not palimdromen");
      }
  }/* the program is written for LINUX users */

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions