User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 426,465 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,240 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 16713 | Replies: 5
Reply
Join Date: Jul 2004
Posts: 2
Reputation: Kerry is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Kerry Kerry is offline Offline
Newbie Poster

Solution how to reverse a numbers input by user

  #1  
Jul 26th, 2004
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Posts: 1
Reputation: saadkhulsai is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
saadkhulsai saadkhulsai is offline Offline
Newbie Poster

Re: how to reverse a numbers input by user

  #2  
Jul 26th, 2004
U Means how to make a factorial program then mail me at saadkhulsai@yahoo.com
Reply With Quote  
Join Date: May 2004
Posts: 251
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Rep Power: 6
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: how to reverse a numbers input by user

  #3  
Jul 26th, 2004
Originally Posted by Kerry
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;
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote  
Join Date: Jul 2004
Posts: 16
Reputation: rishiraj_bayerd is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
rishiraj_bayerd rishiraj_bayerd is offline Offline
Newbie Poster

Re: how to reverse a numbers input by user

  #4  
Jul 27th, 2004
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<stdio.h>
#incliude<conio.h>


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 rishi_works@yahoo.co.in

thanking you......
Rishiraj bayerd.
Reply With Quote  
Join Date: Aug 2004
Location: india,AP
Posts: 17
Reputation: let us c is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
let us c's Avatar
let us c let us c is offline Offline
Newbie Poster

Re: how to reverse a numbers input by user

  #5  
Aug 19th, 2004
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.
Reply With Quote  
Join Date: Aug 2004
Posts: 11
Reputation: stg110 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
stg110 stg110 is offline Offline
Newbie Poster

Re: how to reverse a numbers input by user

  #6  
Aug 19th, 2004
the recursive code (function call itself ) will be as follow
#include <iostream>
#include <cstdlib>
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<<reverse_num(n,0)<<endl; //calling the function
system("pause") ;
return 0;
}
int reverse_num(int n,int m)
{
if(n==0)
return m; //base (exit condition)
m*=10;
m+=n%10;
return reverse_num(n/10,m); //recursive call
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 3:49 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC