# C language I blog assignment 03

2020-11-07 20:15:15 GitHub\$

Which course does this assignment belong to https://edu.cnblogs.com/campus/zswxy/CST2020-4
Where are the requirements for this assignment https://edu.cnblogs.com/campus/zswxy/CST2020-4/homework/11455
The goal of this assignment Learn how to use for Statement to achieve a specified number of cycles , Improve your ability to write and analyze code
Student number 20209058

## 1.PTA Experiment assignment

from PTA Choose the topics in a group 3 You are most satisfied with the following topics , The more difficult it is to choose a topic , Higher score , Each question 2 branch , The content requirements are as follows ：
1.1 Before finding a simple interleaved sequence N Xiang He
This question requires the preparation of procedures , Calculation sequence 1 - 1/4 + 1/7 - 1/10 + ... Before N Sum of items .
1.1.1 Screenshot of experimental code 1.1.2 Data processing

`````` Data expression : use flag It means the first one i Item symbol , The initial value is positive ,denominator It means the first one i The denominator of the item , For the initial 1,item Store the value of each item ,sum Store the accumulated value , among flag,i,denominator,N Is an integer ,item and sum Double precision floating point .
Data processing : Using assignment statements and simple four operations to calculate sum, Reuse for Cycle accumulation sum Value .
``````

1.1.3 PTA Submit list and description • Q1: There was a format error at the beginning of the run
• A1: Look carefully at the title, it turns out that there is no space on either side of the equal sign , Have to say ,pta It's very strict

1.2 Before the sequence of fractions N Xiang He
This question requires the preparation of procedures , Calculation sequence 2/1+3/2+5/3+8/5+... Before N Sum of items . Notice that the sequence starts from 2 Xiang Qi , The numerator of each term is the sum of the former and the denominator , The denominator is the numerator of the former .
1.2.1 Screenshot of experimental code 1.2.2 Data processing

`````` Data expression ：z The molecule ,m The denominator ,i On behalf of each ,item Store the value of each item ,sum It's the result of the whole equation , The integer data has z,m,i,N, Floating point data has sum,item.
Data processing ： use for Statements are accumulated , utilize m=m-z To assign the value of the previous molecule to m
``````

1.2.3 PTA Submit list and description • Q1: I didn't see the problem clearly at first , Running result error
• A1: Read the title and code again , Original denominator assignment error , Direct will z The value of is assigned to the denominator , And then z The value of has changed

1.3 The digital pyramid
This problem requires the realization of function output n Line number pyramid .
1.3.1 Screenshot of experimental code 1.3.2 Data processing

`````` Data expression ： take j It is expressed as the number of spaces to be output on the left side of each line ,i For each line , among i,j All are integers
Data processing : At the first for You need to nest two more for sentence , In addition, use a simple one print sentence
``````

1.3.3 PTA Submit list and description • Q1: In the compilation result , There has been a problem that the return value is ignored
• A1: In defining pyramid() Function time , It should be understood that the function of this function is the output pyramid , Don't do any calculations , So there is no return value
• Q2: In the run result , The pyramid structure is not output correctly
• A2: the last one printf In the sentence ,%d Forget to add a space after

Find a good code , Understand code functions , And tell us what you can learn from the code you have chosen .
as follows ： Check the price of the goods in the vending machine • Take advantage of for Cycle through the menu , Simple and easy to understand
• break Statement can cause a program to jump out of a loop when a condition is satisfied
• switch Statement to implement multi branch structure , According to the number entered by the user , The corresponding price can be assigned to price, Make the program look simple and rigorous
• In the future, we can use this simple statement to realize some complex functions , Make the code as simple as possible

## 3. Learning summary

3.1 Learning progress bar

Zhou / date Time spent this week Lines of code Brief introduction of the knowledge learned At present, there are some doubts
Week eight 10.19-10.25 10h 30 Simple input and output functions nothing
Week 9 10.26-11.1 20h 100 Define basic data types , Correct use of format control string nothing
Week 10 11.2-11.8 25h 200 for Loop and call simple mathematical functions I don't know which functions can be called directly without defining

3.2 Accumulate lines of code and blog words 3.3 Learn to understand

• I learned only one of them this week for Loop statement , But a lot of questions can be applied to it
• Although some problems seem complicated , But just find the key function to implement its function , Define data correctly , It's all over the place
• of c Many concepts and sentences of language have not been learned , Some of the topics are very simple , It's complicated by me , This requires me to spend more time learning