11185 - Ternary

#include <stdio.h> 

int main() 
  { 
  long a,data[100],i; 
  while(scanf("%ld", &a) && a>-1) 
   {
    i=0; 
    if(a==0)
      printf("0\n");
    else
    {
    while(1) 
        { 
        data[i]=a%3; 
        a=a/3; 
        if(a==0) 
          break; 
        i++; 
        } // End of convertion 
 
 
       for(long j=i;j>=0;j--) 
          printf("%d",data[j]);
       printf("\n"); 
    }
    }//End of while 
  } // End of main

Comments

Popular posts from this blog

371 - Ackermann Functions

Create many folder with one click