954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to reverse a numbers input by user

Hello, my name is kerry and i just sign up .Well, my question is how do reverse a number input by user using recersive function.Thanks for the help.

Kerry
Newbie Poster
2 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

U Means how to make a factorial program then mail me at [email]saadkhulsai@yahoo.com[/email]

saadkhulsai
Newbie Poster
1 post since Jul 2004
Reputation Points: 10
Solved Threads: 0
 
Hello, my name is kerry and i just sign up .Well, my question is how do reverse a number input by user using recersive function.Thanks for the help.

You mean recursive funtion.The concept is quite simple.You take a number (to be reversed) and divide it by 10 and add the remainder to another number.As every loop goes by you multiply 10 to the other number and keep adding the remainders till you get 0.

Check this out

int n=12345,m=0;
cout<<"Orginal No:"<<n;
while(n>0)
{
    m *= 10;
    m += n%10;
    n /= 10;
}

cout<<"\nRevesed No:"<<m;
FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

Hi,
Your problem can be solved in various way.This program is simplest(but layman process).Here i assumed that input number is in between integer range
(i.e.-32768 to 32767)

#include
#incliude


void reverse(int num)
{
int i,div;

for(i=0;i<5;i++)
{
if(num>9)
{
printf("%d",div);
break;
}

div=num%10;
num*=/10;
printf("%d",div);
}

}

void main()
{

int num;
clrscr();

printf("\nEnter the number:");
scanf("%d",&num);

reverse(num);

getch();
}


N.B.
If you have any problem in C.Please send it to me with your id.I try my best to solve it.my id is [email]rishi_works@yahoo.co.in[/email]

thanking you......
Rishiraj bayerd.

rishiraj_bayerd
Newbie Poster
16 posts since Jul 2004
Reputation Points: 13
Solved Threads: 0
 

reverse(int n)
{
long sum=0;int rem;
while(n>0)
{rem=n%10;
sum=sum*10+rem;
n=n/10;}
return sum;

main()
................................ hope u can do it from here.good luck.

let us c
Newbie Poster
17 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

the recursive code (function call itself ) will be as follow
#include
#include
int reverse_num (int n,int m) ;
using namespace std;
int main()
{
int n;
int m=0;
cout<<"enter number to reverse :";
cin>>n;
cout<

stg110
Newbie Poster
11 posts since Aug 2004
Reputation Points: 11
Solved Threads: 0
 
#include<stdio.h>
#include<conio.h>
main()
{
int num, rem=0;
printf("\n Enter the number ");
scanf("%d", &num);
while(num>0)
{
rem = (rem * 10) + (num % 10);
num = num / 10;
}
printf("\n Reverse of the number is %d", rem);
getch();
}
c0ld sn1ff3r
Newbie Poster
5 posts since Oct 2008
Reputation Points: 6
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You