The decimal (base ten) numeral system has ten possible values (0,1,2,3,4,5,6,7,8, or 9) for each place-value. In contrast, the binary (base two) numeral system has two possible values, often represented as 0 or 1, for each place-value.
In this program if you enter 15 as input(decimal no) then output is 1111 as in binary.
Following is a source code of decimal to binary program in c language.
#include<stdio.h>
#include<conio.h>
void main()
{
int dec, i=0, j;
int binary[50];
clrscr();
printf("Enter Decimal No : ");
scanf("%d",&dec);
while( dec > 0 )
{
binary[i] = dec % 2;
i++;
dec = dec / 2;
}
for(j = i-1; j >= 0; j--)
{
printf("%d", binary[j]);
}
getch();
}
0 comments :
Post a Comment