Product
Product |
The Problem
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
The Output
For each input pair of lines the output line should consist one integer the product.
Sample Input
12 12 2 222222222222222222222222
Sample Output
144 444444444444444444444444
#include <stdio.h>
#include <string.h>
void multiply (char n[],char s[],char m[])
{
int i,j,k,len1,len2,r[600];
memset(r,0,sizeof(int)*600);
len1=strlen(n);
len2=strlen(s);
for(i=len1-1;i>=0;i--)
for(j=len2-1,k=599-(len1-1-i);j>=0;j--,k--)
r[k]+=(n[i]-48)*(s[j]-48);
for(i=599;i>=0;i--)
if(r[i]>9)
{
r[i-1]+=r[i]/10;
r[i]%=10;
}
k=0;
while(r[k]==0&&k<=598)k++;
for(i=k,j=0;i<=599;i++,j++)
m[j]=r[i]+48;
}
int main()
{
char s[600],n[600],m[600];
while(scanf("%s%s",&s,&n)!=EOF)
{
memset(m,'\0',sizeof(char)*600);
multiply(n,s,m);
printf("%s\n",m);
}
return 0;
}