C Program to Convert Decimal Number into Binary



In this program we will convert decimal number into binary number.



  1. // C program to convert decimal to binary
  2. #include <stdio.h>
  3. #include <math.h>
  4. long decimalToBinary(int decinum)
  5. {
  6. long binum = 0;
  7. int rem, temp = 1;
  8. while (decinum!=0)
  9. {
  10. rem = decinum%2;
  11. decinum = decinum / 2;
  12. binum = binum + rem*temp;
  13. temp = temp * 10;
  14. }
  15. return binum;
  16. }
  17. int main()
  18. {
  19. int decinum;
  20. printf("Enter a Decimal Number: ");
  21. scanf("%d", &decinum);
  22. printf(" Binary Number is: %ld", decimalToBinary(decinum));
  23. return 0;
  24. }

Output
Output!
download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube