Program in C to print the binary equivalent 1 to nth number.
#include<stdio.h> #include<conio.h> void main() { long int bin,dec,base,i,n; clrscr(); printf("Enter a number:-"); scanf("%lld",&n); for(i=1;i<=n;i++) { dec=i; for(bin=0,base=1;dec!=0;dec=dec/2) { bin=dec%2*base+bin; base=base*10; //dec=dec/2 } printf("%ld binary = %ld\n",i,bin); } getch(); }
Output :-
0 Comments