C program for the shortest calculation of the multiplication of large numbers

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.