1//高精度預處理
2 scanf("%s"
,s);
3 n=strlen(s);
4for(i=1;i<=n;i++) //
字串處理
5 a[n-i+1]=s[i-1]-48
;6 a[0]=n; //
a[0]儲存第乙個數的長度
7 scanf("%s"
,s);
8 n=strlen(s);
9for(i=1;i<=n;i++)
10 b[n-i+1]=s[i-1]-48
;11 b[0]=n; //
b[0]儲存第二個數的長度
1//高精度加法
2void plus(int *a,int *b)315
}16if(c[l+1]>0) l++;
17 c[0]=l;
18 }
1高精度減法21
、呼叫方法:
3 a0=a[n];
4 b0=b[n];
5if((a[0]>b[0])||((a[0]=b[0])&&(a0>b0)))
6minus(a,b);
7else 82
、函式9
void minus(int *a,int *b)
1022}23
while(l>1&&c[l]==0)l--;
24 c[0]=l;
25 }
1高精度乘法
2void multiply(longq)3
12 l++;
13while(b[l]>=10)14
19while(l>1&&b[l]==0) l--;
20 b[0]=l;
21 }
需要注意的是陣列的初始化
高精度模板
include include include includeusing namespace std define maxn 9999 define maxsize 10 define dlen 4 class bignum bignum const int 將乙個int型別的變數轉化為大數 big...
高精度模板
include include include include include using namespace std const int maxn 1000 struct bign bign operator const char num 過載運算子 bign const char num 支援初...
高精度模板
include include include includeusing namespace std define maxn 9999 define maxsize 10 define dlen 4 class bignum 建構函式 bignum const int 將乙個int型別的變數轉化為大...