Write a program that will read a positive integer and determine and print its binary equivalent.
(Hint: The bits of the binary representation of an integer can be generated by repeatedly dividing the number and the successive quotients by 2 and saving the remainder, which is either 0 or 1, after each division.)
#include <stdio.h>
void main()
{
int num,i;
clrscr();
printf("Enter the no. to be printed in binary:");
scanf("%d",&num);
while(num!=0)
{
printf("%d",num%2);
num=num/2;
}
getch();
}
(Hint: The bits of the binary representation of an integer can be generated by repeatedly dividing the number and the successive quotients by 2 and saving the remainder, which is either 0 or 1, after each division.)
#include <stdio.h>
void main()
{
int num,i;
clrscr();
printf("Enter the no. to be printed in binary:");
scanf("%d",&num);
while(num!=0)
{
printf("%d",num%2);
num=num/2;
}
getch();
}
No comments:
Post a Comment