Advertisement
Babul_420

11185 - Ternary

Apr 23rd, 2018
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     long long int num,a[100],r,i;
  6.     while(cin>>num && (num>=0))
  7.   {
  8.       i=0;
  9.       if(num==0)
  10.         cout<<"0";
  11.  
  12.             while(num>0){
  13.                 a[i++]=num%3;
  14.                 num/=3;
  15.             }
  16.     for(long long int j=i-1;j>=0;j--)
  17.         cout<<a[j];
  18.     cout<<"\n";
  19.     }
  20.  
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement