【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;
}

上一篇:PIXOR Real-time 3D Object Detection from Point Clouds 中文译文


下一篇:SQL Sever Josn相互转化