當前位置:首頁 » 編程軟體 » 編程高精度

編程高精度

發布時間: 2025-02-05 10:22:28

c語言編程 高精度加減法

等十分鍾
在給你寫
加法函數
好久沒寫程序了
本來以為十分鍾能寫好
。。。。。(修改:修復了個小bug)
void
plus(char
*a,
char
*b,
char
*c){
int
i,index_a,index_b,index_c,carry=0,ten='9'+1,temp_index_c;
index_a=strlen(a)-1;
//
index變數指向最末一個數字
index_b=strlen(b)-1;
index_c=index_a>index_b?
index_a:index_b;
temp_index_c=index_c;
if(index_a>=index_b){
for(i=index_b+1;i>=0;i--){
b[i+(index_a-index_b)]=b[i];
}
for(i=0;i<index_a-index_b;i++)
b[i]='0';
}
else{
for(i=index_a+1;i>=0;i--){
a[i+(index_b-index_a)]=a[i];
}
for(i=0;i<index_b-index_a;i++)
a[i]='0';
}
while(index_c>=0){
c[index_c]=a[index_c]+b[index_c]+carry-'0';
if(c[index_c]>=ten){
c[index_c]-=ten-'0';
carry=1;
}
else
carry=0;
index_c--;
}
if(carry==1){
for(i=temp_index_c;i>0;i--){
c[i+1]=c[i];
}
c[0]=1;
}
c[temp_index_c+1]=0;
}

熱點內容
java數組的定義方法 發布:2025-03-14 00:53:25 瀏覽:515
壓縮性綳帶 發布:2025-03-14 00:30:21 瀏覽:181
如何給樹莓派編譯適合的軟體 發布:2025-03-14 00:29:45 瀏覽:374
c語言編譯器雲盤鏈接 發布:2025-03-14 00:25:23 瀏覽:346
電腦上哪個游戲可以移植到安卓上 發布:2025-03-14 00:10:32 瀏覽:473
tcl編譯器 發布:2025-03-13 23:52:59 瀏覽:323
linuxnamed 發布:2025-03-13 23:45:29 瀏覽:363
阿里雲30元伺服器 發布:2025-03-13 23:21:25 瀏覽:352
pythonstatvfs 發布:2025-03-13 23:14:55 瀏覽:955
火車上有密碼多少 發布:2025-03-13 23:14:10 瀏覽:867