C program for the shortest calculation of the multiplication of large numbers
# Include
Char s [99], t [99]; int m, n; void r (int I, int c) {int j = 0, k = I; while (k) c + = s [j ++] * t [k --- 1]; if (I) r (I-1, c/10); printf (% d, c % 10);} void main () {gets (s); gets (t); while (s [n]) s [n ++]-= 48; while (t [m]) t [m ++]-= 48; r (m + n-1, 0 );}
?
Note:
1. This program receives two integers input from the keyboard, computes their product, and outputs the result.
The total length of the two integers cannot be greater than 99.
2. This program is useless, just for playing.
3. The main goal of this program is to use the code as short as possible to implement the multiplication of large numbers. The above code
It can be compiled and run in VC. It can be compiled in GCC. The # include statement and the void keyword can be omitted,
Remove carriage return and unnecessary spaces. The total length is only 196 bytes.
In addition, the program deliberately avoids the use of arrays to store intermediate results and final results.
To this end, recursive Programs are used, and the use of recursion also simplifies the code.
4. Do not write such a program in actual work; otherwise, it will be scolded.
5. Do not use this program to test your students and interviewers, even if he claims to be proficient in the C language.
Features of such shortest Program
1. Global variables are often used. The advantage of global variables is that
1). the array and single variable are automatically initialized to 0, saving some variable initialization statements.
2) The array Initialization is 0, which makes the logic simpler and saves some boundary value judgment.
3) In the subroutine, using global variables directly saves some parameter definitions and parameter passing statements.
2. In expressions, many operators such as "++" or "--" are used.
It can effectively shorten the code length. However, I strongly disagree with the use
Such operators.
3. In comparison statements, such statements as if (I> = c) are rarely used, but those such as "if (I )"
This write method is 3 letters less than> = c.