#include <stdio.h>
#include <stdlib.h>
// 函数用于将整数转换为指定基数的字符串表示
char* intToBaseString(int num, int base) {
static char buffer[33]; // 静态数组用于存储转换后的字符串
int i = 0;
int isNegative = 0;
// 处理负数
if (num < 0) {
isNegative = 1;
num = -num;
}
// 转换为字符串
do {
int digit = num % base;
buffer[i++] = digit < 10 ? '0' + digit : 'A' + digit - 10;
num /= base;
} while (num > 0);
// 如果是负数,添加负号
if (isNegative) {
buffer[i++] = '-';
}
// 字符串结束符
buffer[i] = '\0';
// 反转字符串
for (int j = 0; j < i / 2; j++) {
char temp = buffer[j];
buffer[j] = buffer[i - j - 1];
buffer[i - j - 1] = temp;
}
return buffer;
}
int main() {
int n, m, o;
char r[33], s[33], t[33]; // 为字符串分配足够的空间
for (n = 0; n < 8; n++) {
for (m = 0; m < 8; m++) {
o = n + m;
// 调用函数将整数转换为基数为3的字符串
strcpy(r, intToBaseString(n, 4));
strcpy(s, intToBaseString(m, 4));
strcpy(t, intToBaseString(o, 4));
// 输出结果
printf("%s+%s=%s\n", r, s, t);
}
}
return 0;
}