C Language Blog Job--structure

Source: Internet
Author: User
Tags array length

First, the PTA experimental work problem 1:6-1 calculation two complex number of the product 1. PTA Submission List

2. Design Ideas
struct complex{    int real;    int imag;};//该结构体表示复数的实部和虚部struct complex multiply(struct complex x, struct complex y)//定义函数计算复数间的乘法定义struct complex变量result表示函数的返回值result.real=x.real*y.real-x.imag*y.imag计算result的实部result.imag=x.real*y.imag+x.imag*y.real计算result的虚部返回result
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description. Originally wanted to return directly to the expression but there is no way to return the imaginary part and the real part, so set stuct complex variable result and return to the topic 2:7-1 calculate Worker's salary 1. PTA Submission List

2. Design Ideas
struct staff{    char n[10];    float j_money;    float f_money;    float z_money;    float s_money;};//该结构体表示员工姓名,基本工资,浮动工资,支出和实发工资定义struct staff 变量p[999]存放员工信息,定义变量N表示输入员工信息的个数,变量i表示循环次数输入Nfor i=0 to i=N-1输入 员工的姓名,基本工资,浮动工资,支出end forfor i=0 to i=N-1计算员工实发工资=基本工资+浮动工资-支出end forfor i=0 to i=N-1输出员工姓名 实发工资end for
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description. The first set variable p array length is 50 but the hint is not big enough, so set to 999 topic 3:7-2 time conversion 1. PTA Submission List

2. Design Ideas
struct time{    int h;    int m;    int s;}; //该结构体表示时间的小时,分钟,秒设置struct time 变量p设置变量n,k,l表示n秒后经过几分钟,几小时输入起始时间输入n秒IF 起始秒+n秒<60 则秒=起始秒+n否则  k=(起始秒+n秒)/60 , 秒=(起始秒+n秒)%60    //表示超过几分钟IF 起始分钟+k<60 则分钟=起始分钟+k否则 l=(起始分钟+k)/60 ,分钟=(起始分钟+k)%60IF 起始小时+l<24 则小时=起始小时+l否则 小时=(起始小时+l)%24end IF输出新的时间
4. Problems encountered in debugging process and PTA Submission List situation description. I don't understand the relationship between this problem and the structure. Second, this week's topic set PTA Final Ranking

Iii. Reading code 1-If all the elements in an array hold pointers, then we call it an array of pointers.

Arr is an array of pointers that contains 3 elements, each of which is a pointer. Parr is a pointer to an array of arr. The revelation is that we can also store an address in an array, and then set it as an array of pointers, but the definition of Parr should be interpreted as an int (Parr), in parentheses. indicates that Parr is a pointer to an int outside the parenthesesRepresents the type of data that Parr points to. Arr first element is of type int , so add two when defining Parr。 2-Enter a member of a struct type variable and output.

The program uses a nested structure to represent the student information succinctly, pointing to the ratio (*student) in a student-> way. Omitting two characters is more concise. Assign a secure address to the pointer through the function malloc () provided by C. The function sizeof () returns a value that calculates the number of bytes of memory for a given data type. Iv. Study Summary of the Week 1. Summarize what you learned this week.
  • structure, the common body, enumeration, the construction data type characteristics.

    Structs and arrays are structured data types, and arrays are different, and structs can handle different types of data. A common body is a constructed type of multivariate shared storage space that allows several different variables to share the same storage space. Differences between common and structural bodies:
     1.结构体每一位成员都用来表示一种具体事务的属性,共用体成员可以表示多种属性(同一存储空间可以存储不同类型的数据)。 2.结构体总空间大小,等于各成员总长度,共用体空间等于最大成员占据的空间。 3.共用体不能赋初值。 4.共用体变量中的值是最后一次存放的成员的值如   a.i = 1;   a.ch = ‘a‘;   a.f = 1.5;  完成以上三个赋值语句后共用体边量的值是 1.5而 a.i=1 和 a.ch=‘a‘已无意义 共用体变量不能初始化例 union data {  int i;  char ch;  float f;  }a={1,‘a‘, 1.5}  错误!!!
    Definition of a common body form union common body name
    Member List
    Variable list
  • Principle of recursive function

    Recursion (recursion) is a subroutine (or function) calling itself directly or invoking itself indirectly through a series of call statements, which is a basic way to describe the problem and solve the problem.


    Recursion is often used to solve structural self-similarity problems. The so-called structural self-similarity means that the sub-problems constituting the original problem are structurally similar to the original problem and can be solved by a similar method. Specifically, the whole problem can be divided into two parts: the first part is some special cases, there is a direct solution; The second part is similar to the original problem, but smaller than the original problem. In fact, recursion is the conversion of a big problem that cannot or does not solve into one or a few small problems, and then further decomposition of these small problems into smaller problems, until every small problem can be solved directly. Therefore, there are two basic elements of recursion:

    (1) Boundary condition: Determines when recursion is terminated, also known as a recursive exit.

    (2) Recursive mode: Big problem is how to decompose into small problems, also known as recursive body. Recursive functions only have these two elements in order to produce results after a finite number of calculations

    In the recursive function, the calling function and the called function are the same function, it is necessary to pay attention to the recursive function of the call hierarchy, if the call recursive function of the main function is called the No. 0 layer, after entering the function, the first recursive call itself called the 1th layer call, from the level I recursive call itself called the i+1 layer. Conversely, exiting the i+1 layer call should return to layer I.


    The internal execution procedure of recursive function

    A recursive function calls a procedure similar to a nested invocation of multiple functions, except that the calling function and the called function are the same function. In order to ensure the proper execution of recursive functions, a working stack is set up for the system. Specifically, the internal execution of recursive calls is as follows:

    (1) At the beginning of the movement, a work stack is first established for recursive invocation, and its structure includes value parameter, local variable and return address;

    (2) The value parameter of the recursive function and the current value of the local variable and the return address of the call are stacked before each recursive call.

    (3) At the end of each recursive call, stack the top element of the stack so that the corresponding value parameter and local variable revert to the value before the call, and then move on to the location specified by the return address to continue execution.

2. List some of the wrong questions this week.



C Language Blog job-structure

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.