人生如戏的英文:求一个小程序(C语言)

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/30 15:49:50
已知有一个16位的2进制数为1111111100000000,编写一个程序,printf出它的奇数位、偶数位、高八位和低八位。

#include<stdio.h>
#include<string.h>
#define A1 11111111
#define A2 11111111
main()
{int i,a,b;
long c,d,k=10000000,m=1,t=1,temp;
char B1[]={"11111111"},B2[]={"00000000"};
printf("\n");
for(i=8;i>=1;i--)
{temp=A1/k;
if (i!=8) temp=temp-t;
if (t==10) t+=1;
if (temp==1) {printf("%d:j ",i+8);if (i!=8&t!=11) t+=1;t=t*10;}
if (temp==0) {printf("%d:o ",i+8);t*=10;}
k/=10;m*=10;}
m=1;k=100000000;t=1;
for(i=8;i>=1;i--)
{temp=A2/k;
if (i!=8) temp=temp-t;
if (m!=1) t=t*10+1;
if (temp==1) {printf("%d:j ",i);if (i!=8&t!=11) t+=1;t=t*10;}
if (temp==0) {printf("%d:o ",i);}
k/=10;m*=10;}
printf("\ngao8:");puts(B1);
printf(" di8:");puts(B2);
}