Home C Programming Language / Programs / Write a program that will compute the binary equivalent number of a decimal number and print it as output.
🚀 Programming Example

Write a program that will compute the binary equivalent number of a decimal number and print it as output.

👁 873 Views
💻 Practical Program
📘 Step Learning
Write a program that will compute the binary equivalent number of a decimal number and print it as output.

💻 Program Code

#include <stdio.h>

int main()
{

  int a[20],i,m,n,r;
  printf("\n Enter the decimal Integer  ");

  scanf("%d",&n);
  m=n;

  for(i=0;n>0;i++)
  {
    r=n%2;
    a[i]=r;
    n=n/2;
   }

  printf("\n Binary equivalent of %d is \t",m);

  for(i--;i>=0;i--)
    printf("%d",a[i]);

  return 0;

}




                        

🖥 Program Output


 Enter the decimal Integer  10

 Binary equivalent of 10 is     1010
--------------------------------
Process exited after 3.289 seconds with return value 0
Press any key to continue . . .
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.