adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to print the binary equivalent 1 to nth number.

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 :-


Post a Comment

0 Comments