★ The number of inputs into a binary sequence, and statistical sequence of 1 of the number of description: The normal mode in addition to the remainder of the second method is easy to understand, but for the number of inputs are limited to positive and 0, for negative numbers do not adapt, so the use of the method with the post-shift to expand the number of input range. #include <stdio.h>int main () {int M,b,c,i;int count = 0;char a[32];p rintf ("Please enter a number: \ n"), scanf ("%d", &m); for (i = 0; I < 32; i++) {if (M & 1 = = 1) {count++;} c = m & 1; With 0001 and 1 anti 0, the remainder is equal to the effect of modulo (%) b = m >> 1; The whole sequence shifts one bit to the right, equivalent to (/2) the effect m = b;a[i] = c;} printf ("The binary sequence of this number is: \ n"), for (i = >=; I, 0; i--) printf ("%d", A[i]);p rintf ("\ n");p rintf ("The number of 1 in the sequence is: \ n");p rintf (" count=%d ", Count);p rintf (" \ n "); return 0;}
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/E2/wKioL1YJOWPCpdodAADOg0rvK6c319.jpg "title=" Run Test " alt= "Wkiol1yjowpcpdodaadog0rvk6c319.jpg"/>
This article is from the "Warm Smile" blog, please be sure to keep this source http://10738469.blog.51cto.com/10728469/1698928
The number of inputs is converted to a binary sequence, and the number of 1 in the sequence is counted