C Language 11th Blog Job---function nested call

Source: Internet
Author: User

First, the experimental work 1.1 PTA topic Title: Recursive implementation of sequential output integer 1. PTA Submission List

2. Design Ideas
printdigits函数定义整型变量result存放结果if n是10的倍数    result=nelse    取n的个位数赋值给result    递归调用printdigits(n/10)输出result
3. Code

4. Problems encountered in commissioning process and PTA submission List status note

① Recursive exit error. The case of zero is considered wrong.

② Correct after modifying the recursion exit.

1.2 Student performance Management System 1.2.1 Drawing function module diagram, Brief introduction function function 1.2.2 Show your project file 1.2.3 function Code section

Total number of the system code: XXXX
Ask for your head file, insert student information and student score information Code, delete student score information code, total score sort code.
Be sure to include the necessary comments in the code.

1.2.4 Debug Results show

Required to display the menu, the results of each command, the illegal data must have a test and prompt, such as the user number input illegal, or enter the repetition number, indicating that the insertion failed. Query not to the corresponding student information to give tips and so on.
The more tests the sample, the higher the score

1.2.5 debugging encountered problems and solutions. Second, this week's topic set PTA Final ranking. PTA Rankings PTA Submission ListThird, read the code

Title: Integer Splitting
Given an integer n, the total number of possible outputs of this integer split
For example: N==6 has
6
5+1
4+2 4+1+1
3+3 3+2+1 3+1+1+1
2+2+2 2+2+1+1 2+1+1+1+1
1+1+1+1+1+1
A total of 11 decomposition methods, so the output should be 11.

  #include <stdio.h>int q (int n,int m)//n is the number to split, M is the largest value in the split part {if (n = = 1| | m = = 1) return 1;        else if (n < m) return Q (n,n);        else if (n = = m) return 1 + q (n,n-1); else if (n > M) return Q (n,m-1) +q (n-m,m);}     int main () {printf ("Please enter a number to split \ n");     int n;     scanf ("%d", &n);     int ret = 0;     ret = q (n,n);     printf ("The number has a total of split methods \ n");     printf ("%d", ret); return 0; }

Analysis:
① when N=1, there is only one partition {1};
② when M=1, there is only one partition {,.... 1,1,1};
③ when N=m, according to whether the division contains N, can be divided into two situations: (1) The case of the division contains N, only one {n}, (2) The division does not contain n, the use of integers not less than n-1 to split; So at this point q (n,n) = 1 + q (n, n-1).
④ when N<m, it doesn't make sense to use a number larger than N, so this is the equivalent of Q (n,n)
⑤ when N>m, there are two situations:
(1) using m to split N, split out the largest number is m, the rest of the number is added to n-m, the problem becomes the use of an integer less than M to split the n-m, so this time is Q (n-m,m)
(2) split n with a number less than M, split n with a number less than m, expressed as Q (n,m-1)
So at this point q (n,m) = Q (n-m,m) + q (n, m-1).
In conclusion, the ①② belongs to the regression condition, ③④ belongs to the special case, ⑤ is the general situation, belongs to the recursive method, and its essence is to solve the problem by reducing N or M to achieve the regression condition.
Recursive expressions:

Iv. Summary of this week's study 1. Introducing this week's Learning 1.1. Macros (macro substitution)
  • Macro-defined format:#define 宏名标识符 宏定义字符串
    Note:
    1. Not a true C statement, no semicolon at the end of the line
    2. Always use uppercase string as macro name, macro name and macro definition string separated by a space, so the macro name can not use space
    3. Macro definition string is any string, the middle can have a space, with a carriage return to do the end
    4. If the macro definition string is followed by a semicolon, the semicolon is also replaced as a macro when the preprocessing is compiled
    5. Macro definitions can be nested using

    #define PI 3.1415926#define S PI*r*r
  • Use of macros
    1. Symbolic constants, such as the definition of pi, array size
    2. Simple function function implementation
    3. When you need to write some of the same content more than once in a program, you might want to write it as a macro
    Cases:

    #define LONG_STRING "it represent a long string that   is used as an example."

    How to use:printf(LONG_STRING )
    Note:
    1. #define最后面跟的 "" means that the line is not closed, and the next line is combined to become a full row
    2.long_string represents a quoted string, so there is no need to quote in printf ()

  • Macro definition with Parameters
    #define  宏名(参数表)  宏定义字符串
    Note:
    1. parameter list only parameter name, no type description
    2. The macro name and parentheses must be next to each other, and the parentheses cannot be omitted.
    3. If the replacement text has parentheses, the macro substitution must have parentheses, and conversely, if the replacement file itself does not have parentheses, the macro substitution cannot be arbitrarily bracketed.
    4. Macro substitution is not calculated.
    Example: Seeking y= (x+y) 2
    Error:#define SQR(x) x*x 宏替换后 -> y=x+y*x+y≠(x+y)2
    That's right:#define SQR(x) (x)*(x)宏替换后 -> y=(x+y)*(x+y)=(x+y)2

1.2. The file contains
    • file contains the format:
      #include<需包含的文件名>Or#include"需包含的文件名"
      1. Double quotation marks, refers to the system first in the directory where the source program to find the specified include file, if not found, and then according to the system specified by the standard way to find the relevant directory.
      2. Angle brackets, the system will be directly in accordance with the system specified by the standard way to the relevant directory to find.
2. Learning Experience
    • This week's content is a bit confusing, especially the pointer advanced part of the content, but also need to summarize learning.
    • This week's homework student performance management system, code volume increase, is also a new mode of operation, multi-document engineering, I have difficulty.
    • A semester is almost over, some of the previous knowledge points to review the summary, the next should be more busy one months.

C Language 11th Blog Job---function nested call

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.