ccplusplus.com
Learn C, C++ Concepts
Friday, January 13, 2012
how to find reverse of a number in c
/*********************************************************************** * File : find-reverse-of-number.c * Author : Saurabh Gupta * Desc : how to find reverse of a number in c * Source : http://ccplusplus/p/c.html * Created : PM 06:09 13 January 2012 * Note : ************************************************************************/ #include
void main() { int nNumber, nTmp, nReverse=0; printf("Enter any number : "); scanf("%d", &nNumber); while(nNumber>=1) { nTmp = nNumber % 10; nReverse = nReverse * 10 + nTmp; nNumber = nNumber / 10; } printf("Reverse = %d\n",nReverse); } /* * * [sgupta@rhel6x64 c]$ gcc find-reverse-of-number.c -o find-reverse-of-number [sgupta@rhel6x64 c]$ ./find-reverse-of-number Enter any number : 123 Reverse = 321 [sgupta@rhel6x64 c]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment