First, the experimental work 1.1 decimal conversion binary design Ideas
如果n==1 输出1 即递归出口否则如果n>1 dectobin(n/2) 即递归函数 输出n%2的结果否则输出0 即为输入n时直接为0的情况
Code
Debugging issues
In the beginning, the recursive exit is wrong to write the n==0 as a recursive exit but also need to determine the condition of n directly to 0, so the recursive exit should be n==1 time.
1.2 Student performance Management System 1.2.1 Drawing function module diagram, Brief introduction function function
1.2.2 Show your project documents
1.2.3 Function Code Section
- This system code total number of lines: 278
1.2.4 Debug Results show
Enter student information and score information:
To modify student performance information:
Delete Student score Information:
Rank by total:
Revise the scores and then follow the total score:
Exit:
Enter an illegal command:
Enter the number of non-integer and input number less than 12 bits:
Enter the number to repeat:
Enter Phone number error:
Enter phone number The first digit can be + number:
Change Student score input number error and the number has not been entered:
Delete Student score input number error and the school number has not been entered:
1.2.5 debugging encountered problems and solutions
When you create a new file, the compilation is not passed, the function in the new file is not recognized, and you can only re-establish a project to copy the contents of the past.
Second, this week's topic set PTA Final Ranking
Third, read the code 1.
Recursive implementation of binary search
#include <stdio.h> int r_search(int arr[], int low, int high, int k); int main( ) { int key,index,n,i; scanf("%d",&n); int a[n]; for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("输入要查找的关键字:\n"); scanf("%d", &key); index = r_search(a, 0, n-1, key); if(index >= 0) printf("关键字所在位置是:%d \n", index); else printf("没有找到关键字\n"); return 0; } int r_search(int arr[], int low, int high, int k) { int i,mid; if (low>high) i=-1; else { mid=(low+high)/2; if(arr[mid]==k) i=mid; else if(arr[mid]>k) i=r_search(arr, low,mid-1,k); else i=r_search(arr, mid+1,high,k); } return i; }
Using recursion to realize binary search is more concise in form, the binary search is encapsulated into functions, and different recursive formulas are entered into different cases, and the readability is high.
Iv. Summary of the study this Week 1. Introduce this week's learning content
- Nested calls to functions:
The function also contains nested calls to functions called functions, such as:
- Macro definition:
It is used to define an identifier as a string, which is called the macro name, and the defined string is called the replacement text. Simple macro definition Format for #define <宏名> <字符串> example #define pi 3.14159265 , a macro with parameters is defined in the form of a macro definition that is #define <宏名>(<参数表>) <宏体> #define A(x) x used only for substitution. Like what
The answer to this question is a, the macro definition will not help us to add parentheses, but simply replace, this is easy to mistake. At the same time, macro definition can also realize simple function function, very concise.
- Links between engineering documents
The connection between the project file and the global variable requires an external declaration, the variable declaration format extern 变量名表 , the external function call formatextern 函数类型 函数名
- Application and release of dynamic memory:
The malloc function is a dynamic memory request, it requires a header file #include<stdlib.h> , a prototype void *malloc(size_t size) , a parameter of size that represents the number of bytes of memory that needs to be dynamically requested, and if the memory request succeeds, the function returns the starting address of the memory requested, and returns null if the request fails.
The free function is the release of dynamic memory, which also requires a header file, which is #include<stdlib.h> prototyped void free(void *ptr) , must provide the starting address of the memory, and no return value.
Note: malloc is paired with free, and the compiler does not help us release memory, so remember to release it once you have applied dynamic memory.
2. Learning Experience
This week wrote a student Information management system project, did a lot of days, code volume also reached 278 lines, feel the difficulty of writing is still a bit big, especially in the robustness of the project, so I have to change a lot of input into character type, in order to ensure that the input of different types of data, the program does not crash. Now the more difficult to learn, dynamic memory application and release, as well as to learn the list, it is a headache. Playing code or to be down-to-earth, a dozen, practice the truth, has been reading is not understand, only to hit the code encountered problems to solve the later, then encountered this problem will be resolved. A single step forward, only serious treatment of every homework, can be more and more progress, growing.
C Language Blog Job--function nested call