Monday, June 24, 2013

Write a program to convert Decimal to Binary?

Problem
To convert the given decimal no into binary without using in build function , exampla 11 to printed as 1011

Solotion
#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,intex[]={0,1},data[100],i=0,j;
clrscr();
printf("\n enter the no ..");
scanf("%d",&a);
printf("\nthe %d to binary is ",a);

while(a!=0)
{
data[i]=a%2;
i++;
a=a/2;
}
for(i--;i>=0;i--)
{
j=data[i];
printf("%d",intex[j]);
}
getch();
}



Output



Like the Post? Do share with your Friends.

No comments:

Post a Comment