Pages

Saturday 23 February 2019

Program to illustrate reverse of a given number using recursion

Program to illustrate reverse of a given number using recursion 

//reverse of a given number using recursion
#include<stdio.h>
int sum,r;  // global declaration
int reverse(int); // function declaration
int main()
{
 int n,rev;
 printf("enter any value:\n");
 scanf("%d",&n);
 rev=reverse(n);
 printf("%d reverse is = %d",n,rev);
 return 0;
}

int reverse(int n)
 {
 
  if(n != 0)
    {
     r= n % 10;
     sum=sum * 10 + r;
     n = n / 10;
     reverse(n);
    }
   else
     return sum;
}

output:

No comments:

Post a Comment

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...