Problem Description
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
Input
For each case there is a postive number n on base ten, end of file.
Output
For each case output a number on base two.
Sample Input
1 2 3
Sample Output
1 10 11(1)大意:给出你一个十进制的数字,然后转化成二进制,输出。(2)思路:动态规划中,写一个简单的递归即可。每次n/2自后再作为参数递归下去,直到n/2不为真为止。(3)感想:略吧,找到规律,理解递归过程,实现就好了。(4)#include <iostream> using namespace std; void f(int n) { if (n / 2) { f(n / 2); } cout << n % 2; } int main() { int n; while (cin >> n) { f(n); cout << endl; } return 0; }