hdoj 2051 Bitset

Bitset

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
 

Author
8600 && xhd
First introduce a function    itoa (i ,num ,10 );
i ---- the number that needs to be converted into a string
num ---- variable to save the string after conversion
10 ---- Convert the base (ie base) of the number. 10 means to convert numbers in base 10. It can also be 2, 8, 16, etc. the base type you like
Return value: pointer
#include<stdio.h>
    #include<stdlib.h>
    int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		char str[4000];
		itoa (n, str, 2);
		printf("%s\n",str);
	}
	return 0;
    }



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326501651&siteId=291194637