voidshowArray(intarray[], intlen); intmain(void) { /*n位2进制整数相加问题(此处n=3)*/inta[] = {1, 1, 1, 1}, b[] = {1, 0, 0, 1}, c[] = {0, 0, 0, 0, 0}, len=3; for (inti=len, j=len+1; i>=0; i--, j--) { intxor=a[i] ^b[i]; //当前位进行异或运算c[j] =c[j] ^xor; //2021-08-28 11:49:00 算出前一位,只使用位运算符似乎无法做到,留待后期考虑,此处不纠结c[j-1] = (a[i] +b[i] +c[j]) /2; } printf("arry a is \n"); showArray(a, 3); printf("arry b is \n"); showArray(b, 3); printf("arry c is \n"); showArray(c, 4); } voidshowArray(intarray[], intlen) { for (inti=0; i<=len; i++) { printf("%3d", array[i]); } printf("\n"); }