【C语言】高精度加法
作者:互联网
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
int a[200] = { 0 }, b[200] = { 0 }, c[200] = {0},i, t=0,j,p=0,tmp=0;
int lena, lenb,max;
char s[100] = { 0 };
scanf("%s", s);
lena = strlen(s);
for (j=0,i = lena-1; i >=0; i--,j++) //倒序存入数组a 下同
{
a[j] = s[i] - '0';
}
scanf("%s", s);
lenb = strlen(s);
for (j=0,i =lenb-1; i >=0; i--,j++)
{
b[j] = s[i] - '0';
}
for (i = 0; i < 200; i++) //进位计算
{
tmp = a[i] + b[i] + t;
c[i] = tmp % 10 ;
t= tmp / 10;
}
for (j = 199; j>=0; j--) //倒序输出 将前缀0去除
{
if (c[j] != 0)
{
p = 1;
}
if (p)
{
printf("%d", c[j]);
}
}
return 0;
}
标签:tmp,200,lena,高精度,int,lenb,C语言,加法,include 来源: https://blog.csdn.net/qq_36439118/article/details/121267104