C Language Blog Job--structure

Source: Internet
Author: User

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 multiply(struct complex x, struct complex y){     struct complex product;用于存放结果     执行运算        product.real=x.real*y.real-x.imag*y.imag;    product.imag=x.imag*y.real+x.real*y.imag;以得出结果的实部和虚部        返回product
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

The topic 2:7-1 calculates worker's salary 1. PTA Submission List

2. Design Ideas
struct man{    char name[10];    float j,f,z;//分别为 基本工资 浮动工资 支出 实发工资    float s;};//该结构体表示人员,基本工资,浮动工资,支出,实发工资     输入N表示N个人    for i=0 to i=n-1{  输入名字 基本工资 浮动工资 支出  op[i].s执行运算op[i].j+op[i].f-op[i].z}   for i=0 to i=n-1{  输出名字和实发工资}
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

Man op[] At the beginning of the 100000 can not run, after the small to run, initially the basic wage floating wage expenditure is defined for the int type, the answer is wrong; the output does not have multiple loops.

The topic 3:7-5 Rational Number comparison 1. PTA Submission List

2. Design Ideas
struct fraction{    int m,n;//m为分母,n为分子 }; //该结构体表示分母和分子  struct fraction a,b;定义两个数  double x;//用于计算两分数相减   char ch;//用于输出符号  输入ab两个数的分母和分子  x执行运算a.n*1.0/a.m-b.n*1.0/b.m;if x>0  则a>bif x<0  则a<bif x==0 则a=b输出
3. Code

4. Problems encountered in debugging process and PTA Submission List situation description.

X=A.N1.0/A.M-B.N1.0/b.m; At first, no *1.0 results have been output "="

Second, this week's topic set PTA Final ranking.

Third, read the code

An exercise

struct country { int num; char name[10]; }x[5]={1,"China",2,"USA",3,"France",4, "England",5, "Spanish"}; struct country *p; p=x+2; printf("%d,%c",p->num,(*p).name[2]);

P is a pointer to a struct, p = x + 2 is equivalent to: p = x[0 + 2] = x[2];p->num is the operator of the variable that the pointer accesses, and (*P) is the equivalent of the memory that the P points to out of the data, "." The operator accesses its variable name array, X[2].name is "France", the first F subscript is 0, then the letter labeled 2 is a
An exercise

Students whose data is above or equal to the average are placed in the array referred to in B, the number of students above or equal to the average is passed back by parameter n, and the average score is returned by the function value.

Iv. Study Summary of the Week 1. Summarize what you learned this week
    • 1. Structural body
      struct Structure Body name
      {
      Member table columns
      } variable table column;
      Cases:

      struct data{int a;char b;double c;} s1;
    • 2. Shared body
      Union Common body Name
      {
      Member table columns
      } variable table column;
      Column:

      union data{int i;char ch;float f;} a, b, c;
    • 3. Structural and shared body
      Structs: structs and arrays are structured data types, and arrays are different, and structs can handle different types of data.
      Commons: A common body is a constructed type of multi-variable shared storage space that allows several different variables to share the same storage space.
    • 4. Nested invocation of function, calling function cal () in main function main ()

      2. List some of the wrong questions this week.


      The answer d is wrong because the actual argument in the calling function is an integer variable n, and the address of the pointer variable a[9], which is the pointer variable. Because the function's actual parameters and formal parameters should be of the same type, the number is the same. And the two parameters in answer d are integer variables, so d is the wrong answer. The M in answer a is an integer variable, and x is a variable of an array type, and the array name represents the first address of the array, so it is the same as the form parameter type. Answer b is the same as answer a. The variable p in the answer c is an integer variable, and the variable s is a variable of the pointer type.

      Variables are placed in the program's global store, so that the original assignment can be maintained at the next call. This is the difference between a stack variable and a heap variable. Variables tell the compiler with static that they are visible only within the scope of the variable. This is the difference between it and the global variable.

C Language Blog Job--structure

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.