Skip to main content
changed code, removed unnecessary for loop n the beginning, modified while loop
Source Link
Abel Tom
  • 1.2k
  • 1
  • 7
  • 9

C 170170 120 bytes

n,i,m,k[4]={0};f(){for(i=0;i<3;i++)printf("%d",k[i]);puts("");for(m=1;m<=10;m++m=0;m<=10;m++){n=m;i=0;whilen=m;i=0;for(n>0;n;i++){k[i]=n;n>>=1;i++;k[i]=n;n/=2;}for(i=4;i>0;i--)printf("%d",k[i-1]%2);puts("");}}

Ungolfed version:

void f()
{
    int n,i,m,k[4]={0};
 
    for(i=0;i<=3;i++)
       printf("%d",k[i]);
    puts("");

   for(m=1;m<=10;m++m=0;m<=10;m++)
   {
      n=m;
      i=0;
      while(n>0)
      {for(;n;i++)
        k[i]=n;{
        n>>=1; k[i]=n;
        i++; n/=2;
      }  
      for(i=4;i>0;i--)
         printf("%d",k[i-1]%2);

      puts("");
         
   }
 
}

Can definitely be shortened!?

@Ahemone Awesome idea, Thanks!

Should work now! Try it online!

C 170 bytes

n,i,m,k[4]={0};f(){for(i=0;i<3;i++)printf("%d",k[i]);puts("");for(m=1;m<=10;m++){n=m;i=0;while(n>0){k[i]=n;n>>=1;i++;}for(i=4;i>0;i--)printf("%d",k[i-1]%2);puts("");}

Ungolfed version:

void f()
{
    int n,i,m,k[4]={0};
 
    for(i=0;i<=3;i++)
       printf("%d",k[i]);
    puts("");

   for(m=1;m<=10;m++)
   {
      n=m;
      i=0;
      while(n>0)
      {
        k[i]=n;
        n>>=1;
        i++;
      }
      for(i=4;i>0;i--)
         printf("%d",k[i-1]%2);

      puts("");
     
   }
 
}

Can definitely be shortened!?

C 170 120 bytes

n,i,m,k[4]={0};f(){for(m=0;m<=10;m++){n=m;i=0;for(;n;i++){k[i]=n;n/=2;}for(i=4;i>0;i--)printf("%d",k[i-1]%2);puts("");}}

Ungolfed version:

void f()
{
    int n,i,m,k[4]={0};

       
   for(m=0;m<=10;m++)
   {
      n=m;
      i=0;
     
      for(;n;i++)
      {
         k[i]=n;
         n/=2;
      }  
      for(i=4;i>0;i--)
         printf("%d",k[i-1]%2);

      puts("");        
   }
}

Can definitely be shortened!?

@Ahemone Awesome idea, Thanks!

Should work now! Try it online!

Source Link
Abel Tom
  • 1.2k
  • 1
  • 7
  • 9

C 170 bytes

n,i,m,k[4]={0};f(){for(i=0;i<3;i++)printf("%d",k[i]);puts("");for(m=1;m<=10;m++){n=m;i=0;while(n>0){k[i]=n;n>>=1;i++;}for(i=4;i>0;i--)printf("%d",k[i-1]%2);puts("");}

Ungolfed version:

void f()
{
    int n,i,m,k[4]={0};

    for(i=0;i<=3;i++)
       printf("%d",k[i]);
    puts("");

   for(m=1;m<=10;m++)
   {
      n=m;
      i=0;
      while(n>0)
      {
        k[i]=n;
        n>>=1;
        i++;
      }
      for(i=4;i>0;i--)
         printf("%d",k[i-1]%2);

      puts("");
    
   }

}

Can definitely be shortened!?