刚写了个C的,LZ可以看下算法
[CODE]/* 标准文档模板 */
#include "Stdio.h"
#include "Conio.h"
int main(void)
{
char a[]={'1','9','9','9','9','9','9','9','9','9','9'}; //数19999999999
char b[]={'1','9','9','9','9','9','9','9','9','9','9'}; //数19999999999
int result[12]={0}; //存放结果数组
int i = 0, k = 0;
int lena = sizeof(a)-1, lenb = sizeof(b)-1;
int len = ((lena>lenb)?lena:lenb); //最大循环次数
int temp = 0;
for (i=len;i>=0;i--)
{
temp = (a[i]-0x30)+(b[i]-0x30);
if (temp/10 > 0)
{
if (k == len+1) //进位最多为1,设置最高位
{
result[k] = 1;
break;
}
result[k] = result[k]+temp%10;
result[k+1] = result[k+1]+temp/10;
}
else
{
if (k == len+1) //进位最多为1,设置最高位
{
result[k] = 0;
break;
}
result[k] = result[k]+temp%10;
}
k++;
}
printf("Number one is: "); //输出
for (i = 0;i < lena; i++)
printf("%c",a[i]);
printf("\nNumber two is: ");
for (i = 0;i < lenb; i++)
printf("%c",b[i]);
printf("\nThe result is: ");
for (i = len+1;i >= 0; i--)
printf("%d",result[i]);
getch();
return 0;
}[/CODE]