java代码:
package chapter1;
import java.util.Scanner;
public class _1_1_9 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int N;
N = input.nextInt();
String s = "";
while(N!=0){
s = N%2+s;
N/=2;
}
System.out.println(s);
}
}
C++代码:
// 1.1.9cpp.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
int N;
string s = "";
while (cin>>N) {
while (N) {
s = (char)(N % 2 + '0') + s;
N /= 2;
}
cout << s<<endl;
s = "";
}
return 0;
}