Product |
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
For each input pair of lines the output line should consist one integer the product.
12 12 2 222222222222222222222222
144 444444444444444444444444
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44#include <stdio.h> #include <string.h> int a[1000]; int main() { char s1[260], s2[260]; int i, j, k, k1, k2, x, k0, y; while(gets(s1)) { memset(a, 0, sizeof(a)); y = 0; k = 0; gets(s2); if(s1[0] == '0' || s2[0] == '0') printf("0\n"); else { k1 = strlen(s1); k2 = strlen(s2); for(i = k1 - 1, k0 = 0; i >= 0; i--, k0++) { for(j = k2 - 1, k = k0; j >= 0; j--) { x = (a[k]+(s1[i]-'0') * (s2[j]-'0')) / 10; a[k] = (a[k] + ((s1[i]-'0') * (s2[j]-'0'))) % 10; a[k+1] = a[k+1] + x; k++; } } for(i = 600; i >= 0; i--) { if(a[i] != 0 || y != 0) { y = 1; if(i == 0) printf("%d\n", a[i]); else printf("%d", a[i]); } } } } return 0; }