C Language Blog Job-data type

Source: Internet
Author: User
Tags array definition array length

First, the PTA laboratory work Title 1:7-8 judge the legal identifier 1. PTA Submission List

2. Design Ideas
    • 1. Define the variable repeat,i control number of counts, J is used to count the number of characters entered, K is used to count the number of legal characters entered. Defines the character variable Ch.
    • 2. Enter repeat and enter Ch=getchar () to absorb the carriage return.
    • 3. Use the For loop to control the number of times. Repeat the 4th to 8th step.
    • 4. Use the Do-while statement to enter each character one at a time, with the number of J statistics. Repeat steps 5 and 6 to instruct the input character to ' \ n ' and jump out of the loop.
    • 5. Use the IF statement to determine whether the character J is 1 o'clock (the first character) is a letter or an underscore. is the legal character, k+1;
    • 6. Use the IF statement to determine whether J 1 o'clock characters are letters, underscores, and numbers, which are legal characters, k+1;
    • 7. When jumping out of the loop, determine whether K equals J, yes output Yes, otherwise output No.
    • 8. Assign the initial value of J and K to 0, and prepare for the next for loop.
3. Code

4. Problems encountered in commissioning process and PTA submission List status note
    • The problem of not absorbing a carriage return occurs many times in my code and causes the code to be completely wrong. One is repeat did not absorb enter, debugging just hit 4, on the printf ("No"), one is to judge the completion of the method after the non-absorption return, so the second identifier, in order to solve this problem, I do-while before the GetChar, the last is my J and K In the case of a legal identifier is unequal, because I am using the Do-while statement, so the last input enter will be counted into J, and not be counted into K, so add a new if statement. Also the last format error is because I used getchar in the second problem above to induce the format error, reasoning replaced by the printf statement add \ n.

Topic 2:7-10 simple Calculator 1. PTA Submission List

2. Design Ideas
    • 1. Define variables Number1 and number2 to hold the operands on either side of the operator. I control the loop, result stores the results of each operator operation, and J counts the number of errors.
    • 2. Enter Number1, assign the initial value of result to Number1,j to 0;
    • 3. Use for loop, Ch=getchar (), (ch input character is operator)
    • 4. Use the switch statement, case ' + ':
      scanf ("%d", &number2); result+=number2;break;
    • 5. The other three operators are ibid.
    • 6. When the operator is division sign, determine whether it is 0, the output error, and J plus one.
    • 7. The operator is =,break;
    • 8.default:
      printf ("ERROR"); j=j+1;break;
    • 9. After jumping out of the switch statement, if ch= ' = ', output result, jump out of the for loop. If j is not equal to 0, the description has been faulted and also jumps out for the for loop.
3. Code

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

The first time division sign wrong dozen into multiplication sign, C + + debugging once after.

The topic 3:7-6 falls into the number of the traps 1. PTA Submission List

2. Design Ideas
    • 1. Define I control loop variable, sum is cumulative and number is the same as the value of two times sum
    • 2. Input N,sum assigns an initial value of 0
    • 3. With a For loop, assign number to the value of sum (sum is the value of the last loop), and sum must be re-assigned to 0.
    • 4. When the input N is greater than one digit, use the while statement to sum the numbers sum=sum+n%10;
      N=N/10;
    • 5. If N is less than 10,sum direct sum=sum+n (the sum of this step can be accumulated from the fourth step)
    • 6.sum=sum*3+1; then output sum.
    • 7. Use the IF statement if the value of the first loop sum is 13,break. If number equals sum, it indicates that it has fallen into a trap, break.
3. Code

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

This problem is wrong two places, once is each time for the loop sum does not have the initial value, once is the one step statement did not write, but the debugging process forgot. But soon the mistake was found.

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?

The general form of a one-dimensional array definition is: Type an array group name "Array Length"
Initialization is the assignment of the initial value, for example int a [5]={1,2,3,4,5} is to a[0] to a[4] respectively in curly braces in order to assign the initial value. Static arrays are automatically assigned a value of 0 if they are not initialized, otherwise the value of the element is indeterminate. If the array length is not written, the system automatically assigns the array length to the array by the number in the curly braces.

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

The array name indicates that the array allocates the address of the first cell in contiguous memory space, which is the first address. Know the first address, then assume that the int type occupies two bytes, the first address is 4010, you can know the other number of address is 4012, 4014 .... Increasing. This means that you know the first address, the number of bytes per element, and the storage address of the remaining elements can be computed.

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 between them. His advantages are simple expression, good readability and easy use of loop structure.

1.4 Introduction to the selection method, bubble method, direct insertion sort how to sort? Pseudo code display.

Selection method:

    • 1. Define n elements, i,k to control the number of cycles, Idenx to hold the minimum value
    • 2. Assign a value of N to A[n],idenx to K,k=0, that is, assume the first array value is the minimum value.
    • 3.for (i=k;i<n;i++) {
      if (A[i]<a[idenx]) idenx=i;
    • 4. After finding the minimum value, assign it as A[0],k=k+1;idenx=k, repeat the third step, find the minimum value, assign to a[1], and so on.

Bubbling method:

    • 1. Define n elements, I is used to control the number of cycles, Max holds the maximum value. K for Exchange
    • 2. Assign n elements to the array a[n],max=n;
    • 3.for (i=n-1;i>=0;i--) {
      if (A[i]>a[max]) k=a[max];a[max]=a[i];a[i]=k;
    • 4. Output.

Direct insertion Sorting:

    • 1. Define n elements, K to store the selected number,
    • 2. Send n elements to an array of a[n],k=a[0];
    • 3.for (i=1;i<n;i++)
1.5 What is the binary search method? It differs from the order lookup method?

Binary search method is false with n elements, take the first N/2 elements, compared with the element to be found x is equal, equal to the end, otherwise the size, small in the left half to find the middle number, comparison is equal, and so on, until found. The sequential lookup method is equal to the x from the first one. Both of these lookup tables are in ascending order. The binary lookup method is less than the number of comparisons and the search speed is faster.

1.6 How are two-dimensional arrays defined and initialized?

Two-dimensional arrays are defined in the following form:
Type an array group name "row Length" "Column Length"
For example: Int a[3][3]={{1,2,3},{4,5,6},{7,8,9}}, an inner two-dimensional array is planar, so the first column is assigned values to the elements in the array.

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.

Transpose matrix:
int A[c][d];int B[c][d];
for (i=1;i<=c;i++)
for (j=1;j<=d;j++)
B[i][j]=a[j][i];
The upper triangular i<j; symmetrical i=j of the lower triangular i>j;;

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

Matrix

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

Learn the array, but there is no practical use, the feeling may not be too skilled, there are classroom school that the fill in the blanks, the current problem I do not come out. This midterm exam is very poor, sad at the same time I also realize that I have some basic knowledge of the weak, the key moment is not used.

C Language Blog Job-data type

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.