Header Ads Widget

C PROGRAM: Program to convert positive integer number to its binary equivalent in C Language - Sparsh Blog

 Ans:-> 




The program to convert positive integer number to its binary equivalent in C Language 

Program is as follows:--

#include <stdio.h>

#include <math.h>

long decimalToBinary(int decimalnum)

{

long binarynum = 0;

int rem, temp = 1;

while (decimalnum!=0)

{

rem = decimalnum%2;

decimalnum = decimalnum / 2;

binarynum = binarynum + rem*temp;

temp = temp * 10;

}

return binarynum;

}

int main()

{

int decimalnum;

printf("Enter a Decimal Number: ");

scanf("%d", &decimalnum);

printf("Equivalent Binary Number is: %ld", decimalToBinary(decimalnum));

return 0;

}


OUTPUT:---


Enter  a Decimal Number: 56

Equivalent Binary Number is:  111000


Do You Know the answer for this question:-


Click on the Link for the Answer 👇👇

 C EXERCISE: Program to display the sum of the series [ 9 + 99 + 999 + 9999 ...] in C Language:------



THANKU FOR READING THIS ARTICLE ON-

If you want to suggest any changes in the program please feel free to contact us in the comment section or you can reach us using Contact us Page.














Post a Comment

1 Comments

  1. Great share!! Thanks for sharing this code much helpful 🙂

    ReplyDelete

If you want to give any suggestion regarding the post please feel free to Comment below-