First, the PTA experimental work Title 1:7-3 inverted Digital string 1. PTA Submission List
2. Design Ideas
- 1. Define n to indicate the length of the input string, count represents the number to output, I to control the loop
- 2. Cycle 2n-1 times for (i=1;i<=2n-1;i++)
- 3. Start with the previously incremented section (I<=N)
- 4. If n==1,printf ("%d", count);
- 5. Otherwise output printf ("%d", count)
- 6. Get (i>n&&i!=2*n-1) to decrement the output count--
7.if (i==2*n-1&&i!=1), when outputting the last number, printf ("%d", count) without the output space
3. Code4. Problems encountered in commissioning process and PTA submission List status note
The first number after the output has a space, at first did not notice, and later prompted the answer to the error after adding a condition to solve
Topic 2:7-6 falls into the number of traps 1. PTA Submission List2. Design Ideas
- 1.N represents the natural number of inputs, sum represents the next new natural number, n is used for permutation, I is used for looping
- 2. Enter N scanf ("%d", &n);
- 3. Assigning n values to n
- 4. Perform an unconditional loop for (;;)
- 5. Then proceed while (n!=0) {
sum=sum+n%10;//, add up the numbers on each of you.
N=N/10;}
sum=sum*3+1; Calculate a new natural number
- 6. Output printf ("%d:%d\n", i++,sum);
if (sum==n) then end loop
7. Otherwise n=sum,sum=0. Restart cycle (5)
3. Code4. Problems encountered in commissioning process and PTA submission List status note
This problem in dev-c side changed to do right, in PTA directly to. The run timed out because the loop brackets were enlarged and then modified.
Topic 3:7-10 Simple Calculator 1. PTA Submission List2. Design Ideas
- 1. Define velue1,velue2 to represent the number before and after the operation, sum represents the value after one operation
- 2.char CH
- 3. Enter scanf ("%d", &velue1);
- 4. (Ch=getchar ()) = = ' = ') loop
- 5. Enter scanf ("%d", &velue2);
- 6. If velue2==0, the denominator is 0, the output error
- 7. Otherwise switch (CH) {///determine the input character for the corresponding operation
Case ' + ': sum=velue1+velue2;break;//because the subject operation is in order from left to right, so the run is over
Case '-': sum=velue1-velue2;break;
Case ': sum=velue1velue2;break;
Case '/': sum=velue1/velue2;break;
default:printf ("error\n"); return 0;//If other characters, output ERROR
}
- 8.velue1=sum; Assign sum to velue1 for the next operation
9. When the input character is =, The end loop
3. Code{{Uploading-image-65509.png (uploading ...)}}
4. Problems encountered in commissioning process and PTA submission List status note
Do not judge the illegal characters, how to judge the moment, and then remember the switch statement there is a default statement, plus go on it.
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 a one-dimensional array defined and initialized?
Type an array group name [array length]={initial value}
1.2 A one-dimensional array in-memory structure? can draw a description. What does an array name mean?
The array name represents an address constant that holds the first address of the array memory space
1.3 Why use arrays?Using arrays in your program allows you to use the same array variable names for a group of variables of the same type, using subscripts to differentiate each other. It has the advantages of simple expression, good readability and easy use of circular structure.
1.4 Introduction to the selection method, bubble method, direct insertion sort how to sort? Pseudo-code display. Selection Method:
- 1. Defining the variable I,index,n,k,temp
- 2.int A[10]
- 3. Assigning values to arrays
- 4.for (k=0;k<=n-1;i++) {
Index=k;//index Store the minimum value of the subscript
for (i=k+1;i<n;i++)//Find subscript with minimum value
if (A[i]<a[index]);//The smallest element is interchanged with the element labeled K;
Index=i;
Temp=a[index];
A[INDEX]=A[K];
A[k]=temp;
}
5. Output data
Bubbling method (direct writing of main part)
- 1.int i,j,t;
2.for (i=1;i<n;i++)//external loop
for (j=0;j<n-1;j++)//Internal loop
if (A[j]>a[j+1]) {//Compare two-digit size
t=a[j];a[j]=a[k+1];a[j+1]=t;} If the previous element is large, the interchange
Direct Insert Sort
Direct Insertion Method:
- 1. Starting from the second number comparison
- 2. If the number of comparisons is smaller than the previous number, insert to the previous position
3. Repeat the second loop until there is no number in front of the number or the previous number is larger than its value
1.5 What is the binary search method? It differs from the order lookup method?
- Binary search, also known as binary lookup, is a highly efficient method of finding.
- The basic idea of binary search is: (Set R[low. High] is the current search interval)
Difference: The dichotomy is efficient, but only for sequential sequences. Sequential lookups are relatively slow, but can be used in unordered sequences
1.6 How are two-dimensional arrays defined and initialized?
- Type an array group name [President degree] [column length]
- Initialization can be assigned by rows, or it can be assigned in order. These two results are the same.
For example, by line a[3][3]={{1,2,3},{4,5,6},{7,8,9}
Sequentially a[3][3]={1,2,3,4,5,6,7,8,9}
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 state.
- Matrix transpose can be achieved by the row and column subscript interchange
I>=j symmetric matrix i=j of upper triangular i<=j in lower triangle
1.8 What is the general application of a two-dimensional array?
Generally used for lists, matrices
2. This week's content, you are not what?
After a test, found that there will not be too much, some of the basic feeling did not understand, the test is very poor. To tell the truth, feel that they do not understand anything, you have to buy a book to tell the teacher's knowledge points are written down, and then the basis to understand. The ability to see programming is not strong, there are a lot of problems to solve. This week the array, also dare not say that they understand how much, but probably already understand, the rest through the PTA consolidation. Study hard, and take the next exam well.
C Language Blog Job-data type