diff options
| author | Richard Qin <richard.qin.001@gmail.com> | 2026-09-15 08:16:43 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.001@gmail.com> | 2026-09-15 08:16:43 +0800 |
| commit | 4022e5c95210631e4aceb08eaf9d9071aa5aefc4 (patch) | |
| tree | a5922559836e45fb3459a3d070367912e1035b1a /tests/upload/bigintadd.sy | |
| download | rcc-4022e5c95210631e4aceb08eaf9d9071aa5aefc4.tar.gz rcc-4022e5c95210631e4aceb08eaf9d9071aa5aefc4.tar.xz | |
Diffstat (limited to 'tests/upload/bigintadd.sy')
| -rwxr-xr-x | tests/upload/bigintadd.sy | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/upload/bigintadd.sy b/tests/upload/bigintadd.sy new file mode 100755 index 0000000..3dfac88 --- /dev/null +++ b/tests/upload/bigintadd.sy @@ -0,0 +1,77 @@ +
+int BigIntarr[2][100];
+int BigIntLength[2];
+int Result[200];
+
+int min(int a, int b) {
+ if (a > b) {
+ return b;
+ }
+ else {
+ return a;
+ }
+}
+
+int add() {
+ int a[100];//加数
+ int b[100];//被加数
+ int c[100] = { 0 };//和
+ int i, j = 0, k;//i用来循环,j表示进位 ,两加数中较小加数的长度放到k里
+ int l1, l2, d;
+ l1 = BigIntLength[0];
+ l2 = BigIntLength[1];
+ k = min(l1, l2);
+ i = 0;
+ while (i < BigIntLength[0]) {
+ a[i] = BigIntarr[0][l1 - 1 - i];
+ i = i + 1;
+ }
+ i = 0;
+ while (i < BigIntLength[1]) {
+ b[i] = BigIntarr[1][l2 - 1 - i];
+ i = i + 1;
+ }
+ i = 0;
+ while(i<k){
+ d = a[i] + b[i] + j;
+ j = d / 10;
+ c[i] = d % 10;
+ i = i + 1;
+ }
+ while (i < l1) {
+ d = a[i] + j;
+ j = d / 10;
+ c[i] = d % 10;
+ i = i + 1;
+ }
+ while (i < l2) {
+ d = b[i] + j;
+ j = d / 10;
+ c[i] = d % 10;
+ i = i + 1;
+ }
+ if (j > 0) { c[i] = j; i=i+1; }
+ j = 0;
+ k = i - 1;
+ while (k > -1) {
+ Result[j] = c[k];
+ k = k - 1;
+ j = j + 1;
+ }
+ return j;
+}
+
+int main()
+{
+ int n;
+ int i = 0;
+ BigIntLength[0] = getarray(BigIntarr[0]);
+ BigIntLength[1] = getarray(BigIntarr[1]);
+ n = add();
+ i = 0;
+ while (i < n) {
+ putint(Result[i]);
+ i = i + 1;
+ }
+ return 0;
+}
\ No newline at end of file |
