WRITE A C PROGRAM TO PRINT BINARY EQUIVALENT OF AN INTEGER
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=0;
printf("Enter a number:");
scanf("%d",&n);
while(n!=0)
{
a[i]=n%2;
n=n/2;
i++;
}
printf("The binary equivalent:");
i--;
while(i>=0)
{
printf("%d",a[i]);
i--;
}
getch();
}
Output:
Enter a number:9
The binary equivalent:1001
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=0;
printf("Enter a number:");
scanf("%d",&n);
while(n!=0)
{
a[i]=n%2;
n=n/2;
i++;
}
printf("The binary equivalent:");
i--;
while(i>=0)
{
printf("%d",a[i]);
i--;
}
getch();
}
Output:
Enter a number:9
The binary equivalent:1001
No comments:
Post a Comment