Example : (125)10 =(?)2
Solution:
Write in reverse order to get binary no:=(1111101)2
C Program:
#include<stdio.h>
void main()
{
int n,i=0,bin[20];
printf("\nEnter a Decimal no.");
scanf("%d",&n);
while(n>0)
{ bin[i]=n%2;
n=n/2;
i++;
}
printf("\nEquivalent Binary no is:");
for(--i;i>=0;i--)
printf("%d",bin[i]);
}
Solution:
Write in reverse order to get binary no:=(1111101)2
C Program:
#include<stdio.h>
void main()
{
int n,i=0,bin[20];
printf("\nEnter a Decimal no.");
scanf("%d",&n);
while(n>0)
{ bin[i]=n%2;
n=n/2;
i++;
}
printf("\nEquivalent Binary no is:");
for(--i;i>=0;i--)
printf("%d",bin[i]);
}
Enter a Decimal no.125
Equivalent Binary no is:1111101
No comments:
Post a Comment