# UVa 11185 ### 題目連結:[UVa11185](https://domen111.github.io/UVa-Easy-Viewer/?11185) ### 題述 #### 給你十進位的數字 N,請你把他轉換成 3 進位。 #### 輸入包含多組測試資料。每組測試資料一列有1個整數N(0<=N<1000000001)。 #### 當 N<0 時,代表輸入結束。 ### c++ code: ```cpp= #include<iostream> using namespace std; void f(int n){ if(n<3){ cout << n; return; } else{ f(n/3); cout <<n%3; } } int main() { long long int n ; while(cin>>n) { if (n<0) break; else{ f(n); cout << endl ; } } return 0; } ``` :::success **``sample input``** 0 1 2 3 10 100 1000 -9 ::: :::success **``sample output``** 0 1 2 10 101 10201 1101001 ::: #### [返回首頁](https://hackmd.io/@fkleofk/APCS#11185) ###### tags: `APCS選修` `C++` `UVa`