ccplusplus.com
Learn C, C++ Concepts
Tuesday, February 21, 2012
decimal to binary conversion in c
/************************************************************************* * File : decimal-to-binary.c * Author : Saurabh Gupta * Desc : decimal to binary conversion in c * Source : http://ccplusplus.com/p/c.html * Created : 8:13 PM Tuesday, February 21, 2012 *************************************************************************/ #include
int toBinary (int); void main() { int nNumDec; printf("\nEnter Any Number in Decimal\t: "); scanf("%d",&nNumDec); toBinary(nNumDec); printf ("\n"); } //function to convert deciaml to binary int toBinary (int n) { int r; r = n%2; n = n/2; if ( n == 0 ) { printf("\nThe binary equivalent is %d",r); return(r); } else { toBinary(n); } printf("%d",r); } /* * OUTPUT * [sgupta@rhel6x86 c]$ gcc decimal-to-binary.c -o decimal-to-binary [sgupta@rhel6x86 c]$ ./decimal-to-binary Enter Any Number in Decimal : 10 The binary equivalent is 1010 [sgupta@rhel6x86 c]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment