A decimal number system is consisting of digits from 0-9 the base of a decimal number is 10. Hence all those numbers made of digits from 0-9 are called decimal numbers.
What is a binary number?
A binary number system is consisting of digits 0 & 1 only therefore the base of this number system is 2. So all the number consisting of these two digits only are called binary numbers.
Program Convert Decimal To Binary In C:
#include<stdio.h>
#include<conio.h>
int main()
{
int a[10],num,i,j;
printf("enter a decimal number");
scanf("%d",&num);
for(i=0;num>0;i++)
{
a[i]=num%2;
num=num/2;
}
for(j=i-1;j>=0;j--)
{
printf("%d",a[j]);
}
return 0;
}
How convert a decimal number into binary number.
in order to convert a decimal number into a binary number we divide the decimal number by the base of binary i.e., divide by 2 and store the remainder at every step until we get a number less than 2.
the follow can be understood with the follow example.
No comments:
Post a Comment