#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
long int decimal_num, rem, quotient;
int binary_num[100], i=1, j;
printf("\n Enter any decimal number : ");
scanf("%ld",&decimal_num);
quotient=decimal_num;
while(quotient!=0)
{
binary_num[i++]=quotient%2;
quotient=quotient/2;
}
printf("\n Equivalent binary value of %d :\n",decimal_num);
for(j=i-1; j>0; j--)/*Print the array in reverse order*/
{
printf("\t%d",binary_num[j]);
}
getch();
}
Run1:
Run2:
Previous Next
#include<conio.h>
void main()
{
clrscr();
long int decimal_num, rem, quotient;
int binary_num[100], i=1, j;
printf("\n Enter any decimal number : ");
scanf("%ld",&decimal_num);
quotient=decimal_num;
while(quotient!=0)
{
binary_num[i++]=quotient%2;
quotient=quotient/2;
}
printf("\n Equivalent binary value of %d :\n",decimal_num);
for(j=i-1; j>0; j--)/*Print the array in reverse order*/
{
printf("\t%d",binary_num[j]);
}
getch();
}
Run1:
Run2:
Previous Next
No comments:
Post a Comment