1樓:張黑牛
/*目標:實現任意位數(1000位以內)的兩個大正整數的加法*/#include
#include
#include
#define maxsize 1000
int max(int a, int b)int main(), n2[maxsize] = , sum[maxsize] = ;
scanf("%s%s", str1, str2);
int len1 = strlen(str1);
int len2 = strlen(str2);
int len = max(len1, len2);
int i;
for(i = 0; i < len1; i++)for(i = 0; i < len2; i++)for(i = 0; i <= len; i++)}i = sum[len] == 0 ? len - 1 : len; // 判斷和的最高位是否為0
for(; i >= 0; i--)
printf("\n");
return 0;}
2樓:黑丶雨
#include
#include
#include
#define size 100 //最高相加位數,可修改;
void fanzhuan(char *x); //反轉字串,方便相加;
char *jiafa(char *x, char *y); //高精度加法函式
int main(void)
;char num2[size] = ;
printf("請輸入第乙個數:");
gets(num1);
printf("請輸入第二個數:");
gets(num2);
printf("相加結果:%s\n", jiafa(num1, num2));
return 0;
}void fanzhuan(char *x)
}char *jiafa(char *x, char *y)
else
}char *t2 = strlen(x) > strlen(y) ? x : y;
for(i = strlen(t1); i < strlen(t2); ++i)
else
}if(jinwei)
temp[i] = '1';
fanzhuan(temp);
return temp;}
超大整數的加法--c語言
c語言「字串大整數加法」這題怎麼做?
3樓:這是我小號
#include
#include
#define maxd 100
int main()
}if(num2[max]) printf("%d",num2[max]);//如果最高位產生進製
for(i=max-1; i>=0; i--)printf("%d",num2[i]);
printf("\n");
}return 0;}/*
*過程如下,假設輸入兩個字串123456和987654,先將這兩個*字串逆轉並且分位儲存到兩個整型陣列裡面(因為做加法時*從低位開始相加),然後就和手工演算法一樣依次相加。*/
4樓:流星不死
# include
# include
int main()
else
}if(k3>k4)
}else
}result[j] = 0;
//puts(result);
c = 0;
for(i=strlen(result)-1;i>=0;i--)result2[c] = 0;
printf("%s",result2);
return 0;
}沒仔細研究
5樓:匿名使用者
分長一倍,會有好多人來搶著做啊
我的想法是定義來好字串 a[n],b[n],c[n],再定義乙個 flag標記是不是進製,初始值是零反轉順序,比如輸入的是 123456,反轉後變成 654321就是讓個位數剛好在 a[0]位置
for迴圈,直到兩個數都到最高位
tmp=a[i]+b[i]-'0'-'0';
c[i]=tmp%10+flag
flat=tmp/10
最後再反回來
6樓:匿名使用者
#include
#include
int a[201],b[201];
char c[201];
int main()
}for(i=s+1;i>=1;i--)
if(a[i]!=0||k==1||i==1)}
c語言 大整數加減法
7樓:匿名使用者
#include
#include
#include
char a[1000],b[1000];
int c[1001];
int x,y,i,j,k;
int blen=0;
int alen=0;
char flag = '+';//用於減法標記負數int subtract(char *a, char *b, int len) else
}return 0;
}int subtraction()
printf("=");
if(alen>blen)
for (i=0;i alen)
for (i=0;i=0;i--)
if (strcmp(a, b) > 0) elsereturn 0;
}int addition()
printf("=");
if(alen>blen)
for (i=0;i alen)
for (i=0;i=0;i--)
else
}return 0;
}int main()
if(a[i]=='-')
alen++;
}output1:
output2:
}**執行結果:
123456789-12345
=+123444444
terminated with return code 0press any key to continue ...
123456+111111
=0234567
terminated with return code 0press any key to continue ...
1000000-1
=+0999999
terminated with return code 0press any key to continue ...
1-1000000
=-0999999
terminated with return code 0press any key to continue ...
//對你的**作了! 希望有助於你的學習。
c語言程式設計:大整數的加減法 50
8樓:鍋嘻懵
用rand()產生隨機數,rand()會產生從0到乙個很大的數,我記不清了,反正很大。如果想出現100以內的,就用rand()%100。你可以定義三個int型整數,兩個表示加或者減的物件,另乙個標示加或者減,因為只要出現兩種情況之一,所以可以用rand()%2,這樣只會有0,1兩種情況來標示加或者減。
下面的就很容易了inta,b,i,c;for(i=0;i<10;i++)else}大致就這樣,希望給你點幫助
9樓:
定義兩個陣列;
輸入數字;
對這兩個字串想加;
我幫你寫個字串相加的函式 其他的你自己去完善吧;
void bignumadd(char * a,char * b,char* c)
;char tempb[64] = {};
char tempc[64] = {};
int j,i1,i2,i3,i4,nextadd;
int tempval1,tempval2,tempval3;
i1 = strlen(a) - 1;
for(j = 0;j<=i1;++j)tempa[j] = a[i1 - j];
i2= strlen(b) - 1;
for(j = 0;j <= i2;++j)tempb[j] = b[i2 - j];
i3 = (i1>i2?i1:i2);
nextadd = 0;
for(j = 0 ;j <= i3;++j )if(tempval3 > 9)
else
tempc[j] = tempval3 + '0';
}i4 = strlen(tempc) - 1;
for(j = 0;j <= i4;++j)c[j] = tempc[i4 - j];
}void main()
;bignumadd(a,b,c);}
c語言中怎麼實現兩個超大整數的相加減乘除
10樓:奧妙的數學開拓
在本題中要實現兩個超大整數的計算,主要是靠快速算式,改變運算的傳統過程,準確無誤的求出結果。例如(1)9988+8899=10000-12+8899=18899-12=18887;(2)980886-88906=980886-90000-6+1100=890880+1100=891980;(3)999786x99999=999786x100000-999786=99978600000-1000000+214=99977600214;(4)8950700÷50000=8950700÷100000x2=89.507x2=179.
014。
11樓:匿名使用者
c語言加減乘除超大數
12樓:
可以將它們化為十六進製制來計算。
108大寫怎麼寫,1089567 5大寫怎麼寫
1089567.5大寫數字金額 壹佰零捌萬玖仟伍佰陸拾柒元伍角 中文大寫金額數字應用正楷或行書填寫,如壹 貳 叄 肆 伍 陸 柒 捌 玖 拾 佰 仟 萬 億 元 角 分 零 整 正 等字樣。不得用一 二 兩 三 四 五 六 七 八 九 十 廿 毛 另 或0 填寫,不得自造簡化字。如果大寫數字一到十書...
excel怎麼寫1 50不重複整數隨機數如a1 m
a1 m1之間能輸出20個資料嗎 你按列輸出吧 a1輸入以下公式 if countif a 1 a 21,a1 1,int rand 50 1,a1 會提示迴圈引用,點確定,工具 選項 重新計算 勾選 迭代計算 迭代次數預設為100.就可以了 下拉複製公式到a21 a1 a20就是你要的資料了。如果...
支票1大寫金額怎麼寫,支票12916 6大寫金額怎麼寫
解答 支票12916.6 大寫金額 壹萬貳仟玖佰壹拾陸圓陸角 轉賬支票大寫金額怎麼填寫 光子洙 轉賬支票金額填寫 1 人民幣 大寫 數字大寫寫法 零 壹 貳 叄 肆 伍 陸 柒 捌 玖 億 萬 仟 佰 拾。注意 萬 字不帶單人旁。舉例 1 289,546.52 貳拾捌萬玖仟伍佰肆拾陸元伍角貳分。2 ...
支票大寫怎麼寫,2016大寫支票怎麼寫
貳零壹陸年零壹月壹拾壹日。支票日期大寫,1月要寫作零壹月。11日,要寫作壹拾壹日。2020年,1月17號支票大寫 貳零貳零年零壹月零壹拾柒日。大寫數字寫法 零 壹 貳 叄 肆 伍 陸 柒 捌 玖 拾。捌月前零字可寫也可不寫,伍日前零字必寫。一 要求 1 日期要大寫,如2008年10月6日,寫為 貳零...
15大寫怎麼讀
這是小數,讀成拾伍萬零陸佰肆拾柒點捌。小數,是實數的一種特殊的表現形式。所有分數和無理數都可以表示成小數,小數中的圓點叫做小數點,它是乙個小數的整數部分和小數部分的分界號。其中整數部分是零的小數叫做純小數,整數部分不是零的小數叫做帶小數。在小數的末尾添上或去掉任意個零,小數的大小不變。我們可以去掉小...