Title Description
Description
Give two positive integers a and B to calculate the value of a-a. Ensure that the number of digits A and B does not exceed 500 digits.
Enter a description input
Description
Read in two positive integers separated by a space
outputs description output
Description
Output A-B value
sample input to
sample
3 12
Sample output Sample
outputs
-9
data
size & Hint
The number of digits of two positive integers is less than 500 bits
Here, when the large number comes in, I select the string to receive, and then convert the character array into an array of integers,
and ensure that the a array is larger than the B array
#include <stdio.h> #include <string.h>int main () {char c[505], D[505];int sum[505], a[505], B[505];memset ( Sum, 0, sizeof (sum));/*gets_s (c); gets_s (d); */SCANF ("%s%s", C, d); int i, J,K, tmp, T,flag = 0;if (strlen (c) > strlen (d) || Strlen (c) = = strlen (d) && strcmp (c, D) >= 0) {for (i = strlen (c)-1, j = 0; I >= 0; I--, j + +) A[j] = c[i]-' 0 '; for (i = strlen (d)-1, k = 0; I >= 0; I--, k++) b[k] = d[i]-' 0 ';} Else{flag = 1;for (i = strlen (d)-1, j = 0; I >= 0; I--, j + +) A[j] = d[i]-' 0 '; for (i = strlen (c)-1, k = 0; I >= 0; I--, k++) b[k] = c[i]-' 0 ';} t = 0;for (i = 0; i < K; i++) {tmp = A[i]-b[i]-t;if (tmp < 0) {tmp + = 10;t = 1;} Elset = 0;sum[i] = tmp;} while (I < j) {TMP = A[i]-t;if (tmp < 0) {tmp + = 10;t = 1;} Elset = 0;sum[i++] = tmp;} for (i = 501; sum[i] = = 0; i--), if (flag = = 1) printf ("-"), while (I >= 0) printf ("%d", sum[i--]);p UTS (""); return 0;}
Subtraction of high-precision exercises