C Language Blog Job--function nested call

Source: Internet
Author: User

First, the experimental work 1.1 PTA topic design Thought
    使用递归思想解题    考虑输入n的多种情况       n==1 输出1       n==0 输出0    否则       递归:n/2    取余输出    
Code

Debugging issues
    • Partially correct, about binary conversion is not familiar, according to the submission prompt "Output is all 1" and "output only the highest bit is 1" modified;
    • Wrong answer, recursive use error, modified output system is incorrect;

    • began to redefine a variable, the idea of error, recursive thinking to solve the good;

      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: 311
1.2.4 Debug Results show
    • The results of the program are not able to achieve the final request, and continue to modify;



1.2.5 debugging encountered problems and solutions
    • Function error when calling function, the connection between functions can not make the program pass, change the formal parameters and corresponding arguments;
    • The input number instruction differs from the display, because the function is not called after the instruction;
Second, this week's topic set PTA Final Ranking

Third, read the Code recursive code:
/* 递归输出循环数,比如输出一组数为:1234,2341,3412,4123*/#include<stdio.h> #include<string.h> #include<stdlib.h> #define m 30//便于修改数据 ,自定义 char s[m];//定义字符数组存放输入字符串 void Input()//输入函数 {     puts("Please input one String!");     scanf("%s",s);   }void XunHuan(char *s,int count)  {     if(count==strlen(s)-1) return;//递归出口     else        XunHuan(s,count+1);//再次调用         char ch=s[0];//将第一个字符用ch保存     for(int i=0;i<strlen(s)-1;i++)//按规律输出各数         s[i]=s[i+1];//将后一个覆盖第一个,即往前移     s[strlen(s)-1]=ch;//将最后一个字符与第一个交换,形成第一个不同的数     puts(s);//输出 } int main()//主函数调用 {          Input();     XunHuan(s,0);     return 0;    }
Output Example:

Small comment: Use the library function to find the length of the string, the use of define macro definition, easy to modify data, improve the efficiency of the Code, the convenience of multiple use, and the use of functions to achieve, easy to layer design, reduce coupling and make the interface and implementation separate, easy to modify later, but also to make the idea clearer, read more logical , you should learn more and use more functions to solve the problem, this problem is to realize the loop number output, at the beginning, I think there is no idea, but to read the code is to use the previous use of the circular movement, constantly put the first number to the last, each time the output, that will appear a number of multiple sorting methods, Can learn a kind of use of recursive return to realize before the circulation of the idea, very good;

Find more code:
/*输出蛇形矩阵*/ /*memset() 函数常用于内存空间初始化,它是对较大的结构体或数组进行清零操作的一种最快方法*/#include<stdio.h>#include<string.h>#define m 10//可以修改 ,调整蛇形大小,如改为 100,即可输入100内的数int main(){    int a[m][m];//定义矩阵大小     int n,x=0,y=0,num;//x、y分别指行、列必须初始化0,否则程序无法执行,因为可能数据过大,num用于测看矩阵     while(scanf("%d",&n)){//不等于-1,保证输入有效,即恒真        memset(a,0,sizeof(a));//对结构体数组a清零       num=a[0][0]=1;//保证初始值正确        while(num<n*n){//保证在要求内矩阵为真            while(x+1<n&&!a[x+1][y])//按规律进行编写                a[++x][y]=++num;           while(y-1>=0&&!a[x][y-1])                a[x][--y]=++num;           while(x-1>=0&&!a[x-1][y])                a[--x][y]=++num;           while(y+1<n&&!a[x][y+1])                a[x][++y]=++num;       }       for(x=0;x<n;x++){//输出蛇形矩阵             for(y=0;y<n;y++){               printf("%2d ",a[x][y]);           }        printf("\n");//用于在恰当的个数换行,实现矩阵的输出        }    }    return 0;}
Output Example:

Iv. Study Summary of the Week 1, introduce the content of this week
    • Learning Structured programming methods: "Top down, step-up refinement, function realization". For the large program code, using the main function to separate, cascade allocation, for example, call a function, in the input of different command numbers to perform different functions, this way not only simplifies the main function, and relatively speaking, the program is more logical, very clear, easy to maintain later;
    • Recursive programming. Seize two key points: recursive exit, that is, the end condition of recursion, to when no longer recursive call down, recursive formula, that is, recursive expression, recursive function gives the law of execution, the computer class self-calculation, do not need to tangle in how to draw;
    • Macro basic definition, format: #define Macro name macro definition string. Through the macro to increase the readability of the program, flexibility, "note" macro content is replaced;
    • Some basic standard header files and compilation preprocessing: file includes (#include), macro definition (#define), conditional compilation;
    • Large program composition, practice writing system. For example: Student management system;
2. Learning Experience
    • This week a pointer to the machine test, but the result is as bad as the pointer this chapter of the study is not very good grasp, the use of the pointer back and do not know how to return, need to take another time to review;
    • With the study of C back, found that more and more things fall, a lot of knowledge points do not understand, the semester is nearing the end, slowly each subject to start the final exam, so found that the efficiency of the classroom is very important, pre-class preview and not preview the difference a lot, usually still pay attention to the details of the grasp;

C Language 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.