ccplusplus.com
Learn C, C++ Concepts
Saturday, September 10, 2011
reverse number using recursion in c
/****************************************************** * File : reverse-given-number-using-recursion.c * Author : Saurabh Gupta * Source : http://saurabhgupta0527.blogspot.com/ * Created : PM 05:33 10 September 2011 *****************************************************/ #include<stdio.h> #include <stdlib.h> #include <unistd.h> int reverse_using_recursion(int,int ); int main() { int nNumber,nReverseNumber=0; printf("Enter a number.. :\t"); scanf("%d",&nNumber); printf("The reversed number is \t%d",reverse_using_recursion(nNumber,nReverseNumber)); printf ("\n"); return 0; } int reverse_using_recursion(int nNumber,int nReverseNumber) { if(nNumber!=0) { return reverse_using_recursion(nNumber/10, nReverseNumber*10 + nNumber%10); } else { return nReverseNumber; } } /* * * [sgupta@rhel54x64 c]$ ./reverse-given-number-using-recursion Enter a number.. : 123 The reversed number is 321 [sgupta@rhel54x64 c]$ */
See also
Other popular tricky C Sample Codes and language Concept
.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment