以下是引用小烧饼在2017-3-14 20:58:43的发言:
感觉过了20位就不行了
试试这样行不:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN
256
main()
{
char num1[MAXLEN], num2[MAXLEN];
gets(num1);
gets(num2);
if (*num1==0||*num2==0||*num1=='0'||*num2=='0')
return;
int num1Len = strlen(num1);
int num2Len = strlen(num2);
char *result = (char*)calloc(num1Len+num2Len+1, sizeof(char));
int i, j;
for (i=num1Len-1; i>=0; i--)
{
for (j=num2Len-1; j>=0; j--)
{
result[i+j+1] += (num1[i]-'0') * (num2[j]-'0');
if (result[i+j+1] > 9)
{
result[i+j] += result[i+j+1]/10;
result[i+j+1] %= 10;
}
}
}
for (i=0; i<num1Len+num2Len; i++)
result[i] += '0';
printf("%s * %s = %s", num1, num2, *result=='0'?result+1:result);
free(result);
}