From e8fd54dc029cdb6ad15ac145bef09983ca7369ef Mon Sep 17 00:00:00 2001 From: smallkun Date: Tue, 1 Apr 2025 23:54:12 +0800 Subject: [PATCH] Auto commit --- 高精度.md | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 高精度.md diff --git a/高精度.md b/高精度.md new file mode 100644 index 0000000..a17b50f --- /dev/null +++ b/高精度.md @@ -0,0 +1,91 @@ +### 高精度加法 + +```c +#include +#include + +int main(){ + char str1[200], str2[200], result[201] = {0}; + int i, j, k = 0, t = 0; + + scanf("%s %s", str1, str2); + i=strlen(str1)-1; + j=strlen(str2)-1; + while(i >= 0 || j >= 0){ + if(i >= 0) t+=str1[i--]-48; + if(j >= 0) t+=str2[j--]-48; + result[k++] = t%10+48; + t /= 10; + } + if(t != 0){ + result[k++] = t+48; + } + + for(i=k-1;i>=0;i--){ + putchar(result[i]); + } + puts(""); + + return 0; +} + +``` + + + +### 高精度乘法 + +```c +#include +#include + +int main(){ + char str1[200], str2[200], temp[200],result[1000] = {0}; + int i, j, k, t; + scanf("%s%s", str1, str2); + + j=strlen(str2)-1; + + while(j>=0){ + k=0; + for(i=strlen(str1)-1;i>=0;i--){ + t = k + strlen(str2)-1-j; + result[t+1] += (result[t] + (str1[i]-48)*(str2[j]-48))/10; + result[t] = (result[t] + (str1[i]-48)*(str2[j]-48))%10; + k++; + } + j--; + } + k+=strlen(str2)-1; + while(result[k]==0) k--;//È¥µô¿Õ¸ñ + + while(k>=0){ + putchar(result[k] + 48); + k--; + } + puts(""); + + + return 0; +} + +``` + + + +### 高精度减法 + +```c +``` + + + + + +### 高精度乘法 + +```c +``` + + +