★ Decimal conversion to binary sequence, and output 1 number, and sequence of odd-even sequence #include<stdio.h>int main () {int m,i,x,y;char a[32];// int is 4 bytes long, accounting for 32 bit bits int count=0;printf ("Please enter a number: \ n"), scanf ("%d", &m);for (i = 0; i < 32; i++) {if (m%2 == 1) //the number of 1 in the statistical sequence {count++;} x = m % 2; // Decimal conversion to binary y = m / 2;m = y;a[i] = x;} printf ("Binary sequence of this number is: \ n");for (i = 31; i >= 0; i--) {printf ("%d", a[i]) ;} printf ("\ n");p rintf ("The number of 1 in this binary sequence is:%d", count);p rintf ("\ n");p rintf ("Odd sequence of this binary sequence is: \ n");for (i &NBSP;=&NBSP;30;&NBSP;I&NBSP;>=&NBSP;0;&NBSP;I&NBSP;-=&NBSP;2) {printf ("%d", a[i]);} printf ("\ n");p rintf ("The even sequence of the binary sequence is: \ n");for (i = 31; i >= 0; i -= &NBSP;2) {printf ("%d", a[i]);} printf ("\ n"); RETURN&Nbsp;0;}
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/E5/wKiom1YJMrCyF8_hAAEYOBp4FVE360.jpg "title=" Run Test " alt= "Wkiom1yjmrcyf8_haaeyobp4fve360.jpg"/>
This article is from the "Warm Smile" blog, please be sure to keep this source http://10738469.blog.51cto.com/10728469/1698922
Decimal is converted to a binary sequence, and the number of outputs is 1, and the sequence of odd and even sequences