体验一下,高精度的算法
/*
* =====================================================================================
*
* Filename: a1087.c
*
* Description: Rainboy_RT
*
* Version: 1.0
* Created: 2014-07-04 14:54:08
* Revision: none
* Compiler: gcc
*
* Author: Rainboy (mn), 597872644@qq.com
* Company: NONE
*
* =====================================================================================
*/
#include <stdio.h>
#define max 100
char str1[max+1],str2[max+1];
int n1[max+1],n2[max+1],n3[max+1];
int lena,lenb,lenc;
int i,j,k,l;
int main(int argc, const char *argv[])
{
scanf("%s",str1);
scanf("%s",str2);
lena = strlen(str1); lenb = strlen(str2);
for (i = 1; i <= lena; i++) {
n1[lena-i+1] = str1[i-1] -48;//高位在后,低位在前
}
for (i = 1; i <= lenb; i++) {
n2[lenb-i+1] = str2[i-1] -48;
}
i =1;j=0;
while ((i <=lena) || (i <= lenb)) {
n3[i] = n2[i]+n1[i] +j;
j = n3[i] / 10;
n3[i] = n3[i] % 10;
i++;
}
if (j >0 ) {
lenc = i;
n3[i] = j;
}
else
lenc = i-1;
for (i = lenc; i >0; i--) {
printf("%d",n3[i]);
}
return 0;
}
原文地址:http://www.cnblogs.com/rainboy/p/3824460.html