A Simple C Program to Convert the Decimal into Binary Numbers. We have used a While loop, Modulus(%) and Division(/) operator for this task. 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
Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of
BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
0 comments:
Post a Comment