First, experimental work 1.1->pta topic (6-5) (1) Design ideas
void printdigits( int n ){ if n小于9(确定数字范围) //输出n的值; else if n大于0 printdigits(n/10);//调用自身 //输出换行符 //输出n的个位数 end else if}
(2) Code
(3) Problems encountered in the commissioning process and PTA submission List status note
- Enter a single number except 0 and 1 to output the wrong result because only the case of n is 0 or 1 and no other number is expected.
- You only need to judge if N is greater than 0 and N is less than or equal to 9: that is, there is only one number of cases.
1.2-> Student Achievement Management System 1.2.1-> drawing function module diagram, briefly introduces function function.
- Cal () Function: console function, implement call function function
- void in_students (): function function for writing student information
- void out_students (): function function for outputting student information
- void Modify (): Enter the appropriate number to implement functional functions to modify specific student information
- void Search_student (): Enter the appropriate number to implement functional functions for finding specific student information
- void Delet_student (): Enter the appropriate number and the corresponding course number to implement function functions to delete specific information for a specific student
- void sort (): A simple sort of function by study number
- void Resort (): Functions reordered by total Score
- int inch (): The function of determining the existence or otherwise of the input number
1.2.2-> Show your project documents
1.2.3-> function Code Part header file:
Insert student information and student performance information code:
Delete Student Score Info code:
Sorting the total number of codes:
1.2.4-> Debug Results Display input: Four students, three courses
Query: When there is no student information stored, when there is student information but the wrong number or input number is correct
- When there is student information but the wrong number: (input on the connection)
1.2.5-> debugging encountered problems and solutions.
- After changing the number from a double to a char type, some of the input statements and the called statements are not changed, resulting in a program crash.
- Only the statements that were called were modified, and some other places were not noticed.
Second, this week's topic set PTA Final ranking. PTA Rankings
Third, read the code
//全排列:从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。#define SWAP(a,b,t) ((t)=(a),(a)=(b),(b)=(t)) //宏定义用来交换两个元素的功能void permutation(char *ch, int min, int max) //min和max确定了需要排序的元素区间 min-max { int i; char temp; if (min == max) //边界条件 { printf("%s\n", ch); } else { for (i = min; i<= max; i++) { SWAP(ch[i], ch[min], temp); //先交换在调用 permutation(ch, min+1, max); //min逐渐逼近max SWAP(ch[i], ch[min], temp); //再交换 } } }
- Advantages: The macro definition implements the function of exchanging elements, which is simpler than the implementation of a new function function, and the output permutation by recursion is a reference code to solve such problems by recursion.
Iv. Summary of the study this week (3 points) 1. Learn about this week 1, macro
- A macro is a preprocessing command.
- When using a macro to perform some operations, pay attention to the precedence between the elements of the operation, and the macro expansion does not include parentheses.
- Macros can be used to define some simple function functions (one line is done).
- Macros are only defined once and can be used multiple times, so using macros can enhance the readability and reliability of your program.
- Parameters passed to macro caution with the self-increment operator | The decrement operator
2. Linked list
- is a dynamic storage allocation of a structure, it can be as needed to open the internal memory cells.
- Each element in a list is called a node, and each node should contain two parts: one for the actual data that the user needs to use, and two for the address of the next node.
- The address portion of the footer is placed with a "null" (for "empty Address"), and the list ends here.
- Delete: Point the address of the next node to the address of the next node of the node to be deleted, that is, after the link is deleted, and then the memory space of the node is released.
- Insert new node: Locate the node you want to insert, point its next node address to a new node, and then point the next node address of the new node to the next node address in the insertion node.
- Nodes may not be contiguous in memory.
3. Apply for dynamic memory
- void *malloc (size_t size); Used to apply, in the header file Stdlib
- For a successful application, you need to specify the type for the returned pointer
- void free (void *ptr), which frees the requested memory space after the requested memory space is not used.
2. Learning experience.
- The study of the linked list allows me to find a new formulation of the student performance management system.
- By learning to apply dynamic memory, you can use memory space precisely, and it is useful to refer to how much memory space is needed.
- The use of macros should be especially cautious, the parentheses must be added, otherwise you may have unexpected small problems (and may be very hidden).
C Language Blog Job--function nested call