# C language I blog assignment 06

Posted by grandeclectus on Sat, 20 Nov 2021 13:56:05 +0100

Which course does this assignment belong tohttps://bbs.csdn.net/forums/csuft_swxy_C?typeId=17321
What are the requirements for this assignmenthttps://bbs.csdn.net/topics/603427602
The goal of this assignmentWrite code with a for loop
Student number20218534

## 1, Homework this week (40 points in total)

#### 1.1 complete PTA homework and give a screenshot of programming questions. The screenshot has its own student number and name identification (0 point if it is not in the form of screenshot) (5 points for each question)

###### 7-1 find the sum of the first N items of the interleaved sequence (15 points)

This problem requires writing a program to calculate the sum of the first N items of the staggered sequence 1-2 / 3 + 3 / 5-4 / 7 + 5 / 9-6 / 11 +.

Input format:
The input gives a positive integer N in one line.

Output format:
Output the value of partial sum in one line, and keep the result to three decimal places.

Input example:

```5
No blank lines at the end
```

Output example:

```0.917
No blank lines at the end
``` ```Data representations: defining int Type variable N,double Type variable ret and sum，And will sum Initialize to 0,.
Data processing: for Cycle will be before N Items and accumulation, for Recycle inside if-else To realize the positive and negative interval. It can be seen from the question that the negative sign is taken when the molecule is even, and the positive sign is taken when the molecule is odd.
``` Programming summary: no problem

###### 7-2 sum of the first N items of the square root sequence (15 points)

This problem requires writing a program to calculate the sum of the first N items of the square root sequence √ 1 + √ 2 + √ 3 +. You can include the header file math.h and call the sqrt function to find the square root.

Input format:
The input gives a positive integer N in one line.

Output format:
In one line, output the value S of the partial sum in the format of "sum = S", accurate to two decimal places. Ensure that the calculation results do not exceed the double precision range.

Input example:

```10
No blank lines at the end
```

Output example:

```sum = 22.47
No blank lines at the end
``` ```Data representations: defining int Type variable n，double Type variable sum，sum Initialize to 0 to prevent accumulation errors.
Data processing: with for Loop nesting outputs the sum of the square roots of 1 to 2.
``` Programming summary: no problem

###### 7-3 change coins (20 cents)

Change a sum of change into 5 cents, 2 cents and 1 cent coins. Each coin is required to have at least one. How many different ways can you change it?

Input format:
Enter the amount of change x ∈ (8100) given in one line.

Output format:
It is required to output various exchange methods in the order of large to small according to the number of nickels, nickels and nickels. One conversion method is output for each line, and the format is: "fen5: number of nickels, fen2: number of nickels, Fen1: number of nickels, total: total number of coins". The last line outputs "count = number of conversions".

Input example:

```13
No blank lines at the end
```

Output example:

```fen5:2, fen2:1, fen1:1, total:4
fen5:1, fen2:3, fen1:2, total:6
fen5:1, fen2:2, fen1:4, total:7
fen5:1, fen2:1, fen1:6, total:8
count = 4
No blank lines at the end
``` ```Data representation: defines integer variables x and sum，And will sum Initialize to 0 to prevent sum Variables are taken arbitrarily by the compiler.
Data processing: with for Loop nesting, the innermost layer is reused if Judge the conditions given by the topic and output the results.
``` Programming summary: partially correct: the number of 5 cents, 2 cents and 1 Penny coins were output in the order from small to large. The problem reading speed was too fast and did not examine the problem carefully.

###### 7-4 sum of exponentiation (15 points)

This problem requires writing a program to calculate sum=2 ¹ + two ² + two ³ + ⋯+2^n . You can call the pow function to find the power.

Input format:
The input gives a positive integer n (≤ 10) in one line.

Output format:
Output in the format "result = calculation result".

Input example:

```5
No blank lines at the end
```

Output example:

```result = 62
No blank lines at the end
``` ```Data representation: defining integer variables n And variables sum，And will sum Initialize to 0, which is very important here.
Data processing: used pow Function exponentiation, a for Loop the first power of 2 to the second power of 2 n Power accumulation and final output.
``` Programming summary: no problem

###### 7-5 print 99 formula table (15 points)

The following is a complete table of the lower triangle 99 formula:

```1*1=1
1*2=2   2*2=4
1*3=3   2*3=6   3*3=9
1*4=4   2*4=8   3*4=12  4*4=16
1*5=5   2*5=10  3*5=15  4*5=20  5*5=25
1*6=6   2*6=12  3*6=18  4*6=24  5*6=30  6*6=36
1*7=7   2*7=14  3*7=21  4*7=28  5*7=35  6*7=42  7*7=49
1*8=8   2*8=16  3*8=24  4*8=32  5*8=40  6*8=48  7*8=56  8*8=64
1*9=9   2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81
```

This problem requires that for any given positive integer N, output part of the formula table from 1 * 1 to N*N.

Input format:
The input gives a positive integer N (1 ≤ N ≤ 9) in one line.

Output format:
Output the lower triangle N*N part formula table, in which the number on the right of the equal sign occupies 4 digits and is aligned on the left.

Input example:

```4
No blank lines at the end
```

Output example:

```1*1=1
1*2=2   2*2=4
1*3=3   2*3=6   3*3=9
1*4=4   2*4=8   3*4=12  4*4=16
No blank lines at the end
``` ```Data representation: define three variables a，b，n；n The number of rows used as the end of the multiplication table.
Data processing: with for Loop nesting, inner layer for Cycle control b Increase to a End, outer layer for Cycle control a Increase to n end.
``` Programming summary: partially correct: I did this problem first, looked at the title and began to write. I thought it was to output the whole 99 multiplication table without inputting variable N

#### ***

1. Learning progress bar (5 points)

Week / dateTime spent this weekCode lineIntroduction to knowledge points learnedAt present, there are some confused problems
11/8-11/1442 hours886recursionWhy does job hopping raise salary faster than promotion?

2 accumulated code lines and blog words (5 points) 3. Learning content summary and perception (5 points)
Content summary:
(1) recursion is divided into direct recursion and indirect recursion:
Direct recursion: function calls itself in the execution process.
Indirect recursion: functions call other functions during execution, and then call themselves through these functions.
(2) four elements of recursion:
1. Recursion should have an exit, that is, an end point. Otherwise, it will cycle all the time until the resources are exhausted
2. The problem is shrinking
3. The problem can be solved by recursion again
4. The solution of the group of subproblems should be the final solution of the problem
Perception:
Write programs to explore the most effective algorithm to achieve, improve their thinking ability, in the future, they can fish in troubled waters, ah bah, like a fish in water.

Topics: C R Language Deep Learning