#include<stdio.h>
int array[100],a,i,count=0,temp;
void binary(int n)
{
if(n>0)
{
array[count]=n%2;
count++;
binary(n/2);
}
else
{
count--;
for(i=0;i<=(count+1)/2;i++)
{
temp=array[i];
array[i]=array[count-i];
array[count-i]=temp;
}
}
}
main()
{
int x=0;
while(x==0)
{
int n;
count=0;
printf("\nEnter a decimal integer: ");
scanf("%d",&n);
binary(n);
printf("The binary form of %d is:\n",n);
for(i=0;i<=count;i++)
printf("%d",array[i]);
printf("\nPress 0 to repeat conversion or any other digit to exit: ");
scanf("%d",&x);
}
}
This blog has been created especially for students who are looking for solutions to simple C/C++/java programs that are usually asked at school/college level. Feel free to query or notify us about any errors.
Pages
E-mail us at prgms4starters@gmail.com for any queries or to share your programs. Please mention the program definition in the subject line.
In case you need help in finishing a program, do mention "incomplete pgm" in the subject line. Our team of experts will do their best to help you.
Click the link to follow this page for updates and reminders: FOLLOW THIS SITE
You can also visit our Facebook page by clicking HERE
**don't forget to participate in the polls at the bottom of the page
Program Code
Subscribe to:
Post Comments (Atom)
We have noticed that 20% of our visitors are still using internet explorer. For a better and faster surfing experience we recommend that you switch to either Google Chrome or Mozilla Firefox. We cannot provide you the downloads but here are the links to sites where you can download them from
Google Chrome - click here to go to site
Mozilla Firefox - click here to go to site
No comments:
Post a Comment