I. PTA Lab Assignment Topic 1:7-4 print diamond pattern

To write a program, print a height of n, composed of "*" a positive diamond pattern.*

Input format: The input gives a positive odd n in a row.

Output format: Outputsa diamond consisting of the N planetary number "", as shown in the example. Each asterisk is followed by a space.

1. PTA Submission List

2. Design ideas on the upper half

- 1, define the variable I to realize the loop of the number of lines, J to realize the loop of the space, k implementation of the cycle, m,n;
- 2, number of inputs: scanf ("%d", &n);
- 3, take odd number and guarantee is positive;
- 4, enter the for Outer loop implementation (N/2) +1 lines, that is, output to the middle row for (i=1;i<=n/2+1;i++);
- 5, the inner Loop realizes the space (j= (N/2) +1-i) *2;j>=1;j--);
- 6, continue nesting loop for (k=1;k<= (2
*i) -1;k++) to achieve* output;
- 7, remember to change line: printf ("\ n");

Lower half

- 8. Continue repeating the following lines for (i=1;i<=n/2;i++)
- 9, prevent the next line of space, first judge: if (i!=1) printf ("\ n");
- 10, the next ibid;

3. Code

4. Problems encountered in commissioning process and PTA submission List status note

- (1) The beginning of the thinking wrong, do not understand how to implement the front space, solve: need to find the line number I and the space relationship;

- (2) Format Error & modification error, inconsistent with the title, multiple changes, the space between the asterisking number, and then the last line should be no empty line, so the bottom half, the last side of printf ("\ n") to the beginning of the for, otherwise it will appear from the lower part of the line, more empty a line ；

Topic 2:7-5 BCD Decryption

The BCD number is a byte that expresses a two-bit decimal number, and each four bits represents a bit. So if the hexadecimal of a BCD number is 0x12, it expresses the decimal 12. But Xiao Ming did not learn BCD, all the BCD number as a binary number converted to decimal output. So BCD's 0x12 is exported to a decimal 18!

Now, your program is going to read into this wrong decimal number and then output the correct decimal number. Tip: You can convert 18 back to 0x12 and then back to 12.

1. PTA Submission List

2. Design Ideas

3. Code

4. Problems encountered in commissioning process and PTA submission List status note

- (1) The topic understanding error, according to the prompt to convert 18 back to hex 0x12, and then converted back to decimal 12, the result is wrong;

- (2) The conversion between the system is not correct, on the basis of the previous problem modification, but more chaotic, and then the calculation found in the first step has been converted into 12, do not need to change, otherwise equivalent to not turn;

Topic 3:7-10 Simple Calculator

Simulates the work of a simple arithmetic device. Assuming that the calculator can only perform subtraction operations, the operands and results are integers, and the four operators have the same precedence, calculated in left-to-right order.

Input format: The input gives a arithmetic calculation in one line, with no spaces and at least one operand. An equal sign "=" indicates the end of the input.

Output format: Outputs the result of a calculation on a single line, or if the division denominator is 0 or has an illegal operator, the error message "error" is output.

1. PTA Submission List

2. Design Ideas

3. Code

4. Problems encountered in commissioning process and PTA submission List status note

- The answer is wrong, you can't lose any value

-the answer only satisfies the output example, and the other number is wrong;

- Modified several times, is still part of the correct, within the specified time can not be corrected;

Second, this week's topic set PTA Final Ranking

Iii. Summary of this week's study 1. What have you learned? 1.1 How is an array of one-dimensional arrays defined and initialized? Initialization of one-dimensional arrays: In the compilation phase, without taking up the running time;

- The general form of a one-dimensional array definition is: Type an array group name [array length];
- Initialization of one-dimensional arrays: Type an array group name [array length] ={initial value table}; For example: A [5] ={1,2,3,3,4}; static char ch [3]= {' P ', ' Q ', ' Q '}; Assign a value to a partial element static int a [5] = {7,6};

1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?

- Array storage: The system allocates a contiguous storage unit in an array of memory, each of which is arranged in the order of the subscripts from small to large;
- One-dimensional array in-memory structure: see the first C language textbook 149-150 pages;
- The array name is an address constant that holds the first address of the array memory space;

A

4010 4012 4014 4016 4018 4020 4022 4024 4026 4028 memory address

9 8 7 6 5 4 3 2 1 0 subscript

Value

1.3 Why use arrays?

- Arrays are all elements in an array of structures that can store multiple elements in memory consecutively must belong to the same data type;
- Reduce memory consumption, code definition variables;

1.4 Introduction to the selection method, bubble method, direct insertion sort how to sort? Pseudo-code display. Selection method: Find a minimum of Min, the subsequent comparison is smaller than min to Exchange;

- 1. Define array a [i];
- 2, Start: for (I =0; i < n-2;i++);
- 3, subscript The value of I is set to the minimum value min
- 4: Array to loop for i = 2 to N-2, if a [i] < min, then a [i] = min;
- 5, repeat the cycle of comparison;
- 6, the value of Min is assigned to a [i], return 1;

Bubbling method: Each time the sorting, from the bottom to the top, if the wrong order, then the exchange position, after the first (n-1) sequencing completed, all the numbers are sorted in order, the larger number is placed in the back;

- 1. Define array a [i];
- 2. Array start subscript: for (i=0;i< n-3;i++)
- 3,: Array loop, for i=0 to N-2, if a [i] > a [i + 1], then exchange a [i] with a [i +1];
- 4, each time the exchange between two numbers requires three operations;

Direct Insert method: Loop to find the position of the insertion, the original array a [i] corresponding to the value of the inserted value, the following array a [i+1] corresponding to the original array a [i] value;

- 1. Define array a [i];
- 2, Start: for (I =0; i < n-2;i++);
- 3. The array is looped for i = 2 to n-2, compared to the previous number starting with the second number; If the previous number is small, it is swapped to the previous position;
- 4, repeat step 3, until the number is not preceded by a number or the previous number larger than it;

1.5 What is the binary search method? It differs from the order lookup method?

The binary search method, also known as binary search, takes full advantage of the order relationship between elements, and its basic idea is to divide n elements into roughly equal two parts, take A[N/2] and X to compare, if X=A[N/2], find x, abort the algorithm, if X<A[N/2], If you continue searching for X in the left half of the array a, if X>A[N/2], simply search for x in the right half of the array A;

differs from the sequential lookup method:

- The dichotomy method is only used to arrange the data in order, which is more efficient than the sequential method, reduces the number of comparisons and moves, reduces the complexity, and the sequential method can be used to find the irregular data with low efficiency.
- The space-memory ratio of the dichotomy method is smaller than the sequential method;

1.6 How are two-dimensional arrays defined and initialized?

- The general form of a two-dimensional array definition is: Type an array group type array name [array length] [array column lengths]
- The general form of two-dimensional array initialization is: Type an array group type array name [array line length] [array column lengths]={{initial value table 1},,{Initial value table k},} ；

1.7 How is the matrix transpose implemented? In the matrix: the relationship between the row label I of the lower triangle, the upper triangle and the symmetric matrix J? Please indicate

- Define the pre-transpose array a [i] [j], the array of row subscript and column subscript interchange, that is, I and J Interchange, you can implement matrix transpose;

Before transpose:

- Upper triangle: i > = j;
- Lower triangle: I < = j;

After transpose:

- Upper triangle: I < = j;
- Lower triangle: i > = j;
- symmetric matrices: A [i] [j] ==a [j] [i];

1.8 What is the general application of a two-dimensional array?

- One is the problem of the need to use the row, column, the use of two-dimensional array is more convenient;
- The second is that it can be applied to describe the square or matrix;

2. This week's content, you are not what?

` int main(void){ float s[6]={1,3,5,7,9}; float x; int i; scanf("%f",&x); for(i=4;i>=0;i--) if(s[i]>x) s[i+1]=s[i]; else break; printf("%d\n",i+1); return 0;`

Write down the results of the following programs:

- (1) If input 4, then output 5 4

- (2) If input 5, then output 3 5 4
- The answer to this question, coupled with this midterm exam, found in the reading process is not enough, need to strengthen;
- For arrays, when defined, and applications are not familiar;
- For data types, in practice operations, including priority issues;
- There are also writing procedures, as far as possible to streamline content, to use more similar to the flag of the symbol language, reduce complexity;

C Language Blog Job-data type