From 4022e5c95210631e4aceb08eaf9d9071aa5aefc4 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Tue, 15 Sep 2026 08:16:43 +0800 Subject: Set up a git repo --- tests/sysy_lvX/test1_2.sy | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 tests/sysy_lvX/test1_2.sy (limited to 'tests/sysy_lvX/test1_2.sy') diff --git a/tests/sysy_lvX/test1_2.sy b/tests/sysy_lvX/test1_2.sy new file mode 100644 index 0000000..3dc1d51 --- /dev/null +++ b/tests/sysy_lvX/test1_2.sy @@ -0,0 +1,105 @@ +int a[1000]; +int b[1000]; +int c[1000]; +int lena; +int lenb; +int lenc; + + +void add() { //b=b+a + int i; + + if (lena>lenb) { + lenc = lena; + } + else{ + lenc = lenb; + } + i=0; + while (i<=lenc) { + c[i] = 0; + i=i+1; + } + i=0; + while (i= 10) { + c[i+1] = c[i+1] + 1; + c[i] = c[i] - 10; + } + i=i+1; + } + if (c[lenc]) { //有进位 数组c的长度+1 + lenc = lenc+1; + } + //b<-c + i=0; + while (i= 10) { + c[i+1] = c[i+1] + (c[i] / 10); + c[i] = c[i] % 10; + } + i=i+1; + } + //最高位的值可能>=10 要展开成多位 + while (c[lenc] >= 10) { + c[lenc+1] = c[lenc+1] + (c[lenc] / 10); + c[lenc] = c[lenc] % 10; + lenc = lenc+1; + } + if (c[lenc]) { //0<最高位<=10 也要长度+1 + lenc = lenc+1; + } + //a<-c + i=0; + while (i=0) { + putint(b[i]); + i=i-1; + } + putch(10); + return 0; +} \ No newline at end of file -- cgit v1.2.3