Analysis of Microsoft C language recursive pen questions

Source: Internet
Author: User
Tags microsoft c

Original question: the output result of the following code is
# Include <stdio. h>
Int a = 0; int count = 0;
Void MysteryFunc (int B ){
If (B = 0 ){
Count ++;
Printf ("% d: % d \ n", count, );
}
 
A = a + B;
 
For (int I = B-1; I> = 0; -- I)
MysteryFunc (I );
}
 
Void main (){
MysteryFunc (5 );
Printf ("\ n % d \ n", );
}
Analysis: The first output parameter count is changed only when B = 0 and increases by 1 by count ++. Therefore, this value can be ignored.
A careful analysis of the title is recursive + loop. For each recursive number, it is recursive from itself to 0. In particular, note that the new recursive number generated in the recursion process will be recursive in sequence,
The typical full binary tree structure is as follows:

As described above, the full binary tree is traversed in the forward Order (that is, the "first order traversal" in the figure) and summed to the corresponding leaf node. Result:
1: 15
2:
3:16
4:
5: 19
6:
7: 20
8: 20
9:
10: 26
11: 27
12: 27



16: 31
31 ---- don't forget there is another 31 (printf ("\ n % d \ n", );)
Challenge: We look forward to a better solution!
Author: "BlankHole"

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.