C语言实现自定义运算符@:偶数位与奇数位相加
#include <stdio.h>
int main() { int a, b, c = 0, i = 0, j = 1; printf('请输入两个整数a和b:'); scanf('%d%d', &a, &b); while (a > 0 && b > 0) { int a_even = (a % 100) / 10; // 取出a的偶数位 int b_odd = (b % 100) % 10; // 取出b的奇数位 int sum = a_even + b_odd + c; // 计算和 if (sum >= 10) { sum -= 10; c = 1; // 进位 } else { c = 0; } i += sum * j; // 将和加到c中 j *= 10; // 位数加1 a /= 100; // a的偶数位向前移2位 b /= 100; // b的奇数位向前移2位 } printf('c = %d\n', i); // 输出结果 return 0; }
原文地址: https://www.cveoy.top/t/topic/lKQu 著作权归作者所有。请勿转载和采集!