#include <stdio.h> /* 2進数の乗算 */ unsigned long multiply(unsigned short a, unsigned short b) { unsigned long x, y, z = 0; int i; x = a; y = b; for (i = 1; i <= 16; i++) { if (y & 1 == 1) z += x; x <<= 1; y >>= 1; } return z; } /* メイン ルーチン */ int main() { unsigned short x, y; unsigned long z; printf("正の整数を入力:"); scanf("%u %u", &x, &y); z = multiply(x, y); printf("%u x %u = %lu\n", x, y, z); return 0; }