Sunday 20 July 2014

How to Convert Number Decimal to Binary in C

Structure of the Problem Requirements 

A Simple C Program to Convert the Decimal into Binary equivalent Numbers. We have used a While loop, Modulus(%) and Division(/) operator . We have used an Array "ar" to store the Binary Output(remainder) for proper formatting of output.



Source Code

#include<stdio.h>
int main()
{
int a=0,b=0,n,i=1,j,k=0;
int ar[10]={0,0,0,0,0,0,0,0,0,0};
printf("\n \n ***************** CONVERT DECIMAL TO BINARY ****************");
printf("\n \n Enter Decimal Number : ");
scanf("%d",&n);
while(n!=0)
{
a=n%2;
b=n/2;
ar[i++]=a;
n=b;
k++;
}
printf(" \n \n BINARY NUMBER : ");

for(j=k+1;j>=1;j--)
{
printf("%d",ar[j]);
}
printf("\n \n ");

return 0;
}

Output of the Program



Conversion between Decimal to Binary
Decimal to Binary Conversion






Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment