Hi , I need the program of reversing a number using recursion.
Ex: if input is 123435 , output to be 534321.
Ex: if input is 123435 , output to be 534321.
function reverse(string)
{
if(length(first(string)) == 1) return string;
return reverse(butfirst(string)) + first(string);
/*
The first function returns the first character of the string
The length function returns the length of a string
The butfirst function returns the string without the first character.
*/
}
if (n == 0)
return;
else
{
digit = num % 10;
rev = rev * 10 + digit;
num = numrv(num / 10);
return rev;
}
}
if(k<(strlen(number)-1)/2)
{
temp=number[k],number[k]=number[strlen(number)-k],number[strlen(number)-k]=temp; // k will start as 0 and increase
//call the function with k+1 argument.
}
return number;
#include <stdio.h>
int factorial (int x)
{
printf("%d",x);
if(x < 5){
factorial(x+1)
}
printf("%d",x);
}
int main()
{
int x =1;
factorial(x);
getchar();
}
Comment