Code:-
#include<stdio.h>
int main()
{
int n,r,i=0,j;
char bin[100],x;
printf("Enter a number\n");
scanf("%d",&n);
while(n!=0)
{
r=n%2;
x=r;
bin[i]=x;
i++;
n=n/2;
}
printf("Binary of the number is: ");
for(j=i-1;j>=0;j--)
printf("%d",bin[j]);
return 0;
}
Output:-
Enter a number
10
Binary of the number is: 1010
0 Comments