-
Title Description:
-
As we all know, data stored in a computer is stored in a binary form.
One day, after Xiao Ming learned c, he wanted to know what kind of a number is a type unsigned int, and what the binary string stored in the computer looks like.
Can you help Xiao Ming? And, Xiaoming does not want the binary string in front of meaningless 0 strings, that is, to remove the leading 0.
-
Input:
-
The first line, a number T (t<=1000), represents the number of numbers required below.
Next there is a T line, each line has a number n (0<=n<=10^8), which represents the required binary string.
-
Output:
-
Outputs a total of T-lines. The binary string that is evaluated for each line of output.
-
Sample input:
-
523535262456275989835
-
-
Sample output:
-
101111000010111101001000000110110111101001111110001101010001011
#include <iostream>using namespacestd;voidPrintbinary (intval) { intarry[1024x768]; intk=0; if(val==0) {cout<<0; } Else { while(val) {arry[k++]=val%2; Val=val/2; } for(inti=k-1; i>=0; i--) {cout<<Arry[i]; }} cout<<Endl;}intMain () {intcount; CIN>>count; for(intI=0; i<count;i++) { intnum; CIN>>num; Printbinary (num); } return 0;}
Or
#include <stdio.h>#include<stdlib.h>intarray[10001]; intMain () {intn,i,k; unsignedintN; while(SCANF ("%d", &n)! =EOF) { while(n--) {k=0; scanf ("%u",&N); if(n = =0) {printf ("0\n"); } Else { while(n) {array[k+ +] = n%2; N= N/2; } for(i = k-1; I >=0; i--) {printf ("%u", Array[i]); } printf ("\ n"); } } } return 0; }
Topic 1473: Binary number