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

編程高精度

發布時間: 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;
}

熱點內容
app什麼情況下找不到伺服器 發布:2025-05-12 15:46:25 瀏覽:714
php跳過if 發布:2025-05-12 15:34:29 瀏覽:467
不定時演算法 發布:2025-05-12 15:30:16 瀏覽:131
c語言延時1ms程序 發布:2025-05-12 15:01:30 瀏覽:166
動物園靈長類動物配置什麼植物 發布:2025-05-12 14:49:59 瀏覽:735
wifi密碼設置什麼好 發布:2025-05-12 14:49:17 瀏覽:148
三位數乘兩位數速演算法 發布:2025-05-12 13:05:48 瀏覽:397
暴風影音緩存在哪裡 發布:2025-05-12 12:42:03 瀏覽:542
access資料庫exe 發布:2025-05-12 12:39:04 瀏覽:630
五開的配置是什麼 發布:2025-05-12 12:36:37 瀏覽:365