Showing posts with label convert. Show all posts
Showing posts with label convert. Show all posts

Monday, February 16, 2015

C program to convert decimal number to binary number

C program to convert decimal number to binary number

#include<stdio.h>

#include<conio.h>

void main()

{
int d,n,i,j,a[50];
clrscr();

printf("Enter a number:");

scanf("%d",&n);

if(n==0)

 printf("
The binary conversion of 0 is 0"):

else
{
printf("
The binary conversion of %d is 1",n);


for(i=1;n!=1;++i)

{
d=n%2;
a[i]=d;
n=n/2;
}

for(j=i-1;j>0;--j)

printf("%d",a[j]);
} getch();
}
Read more »

Sunday, February 15, 2015

C Program to convert a decimal number to binary number


#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int d,n,i,j,a[50];

cout<<"Enter a number:";
cin>>n; cout<<"
The binary conversion of "<<n<<" is 1";
for(i=1;n!=1;++i)
{
d=n%2;
a[i]=d;
n=n/2;
}

for(j=i-1;j>0;--j)
cout<<a[j];

getch();

}
Read more »