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;
}
大数乘法算法实现
本文介绍了一种处理大整数相乘的算法,并提供了一个具体的C语言实现案例。该算法能够有效地处理超过标准整型变量长度的大数乘法问题,通过字符串方式存储大数并逐位相乘的方法,确保了计算的准确性。
344

被折叠的 条评论
为什么被折叠?



