C Language Blog Job--one or two-dimensional array

Source: Internet
Author: User

One, PTA laboratory work. Topic 1:7-2 Finding the number of occurrences in an integer sequence is 1. The results of PTA experiment

2. Design Ideas
    • (1) Definition of N,n,a[1000],x,j,i,max;

    • (2) Input n

    • (3) Definition b[n]

    • (4) assigning values to A[1000],b[n]

    • (5) for (i=0;i<n;i++) {executes nested for (j=0;j<n;j++) if a[i]=a[j],b[i]++;

    • (6) I=0,max assignment B[i]

    • (7) for (i=1;i

    • (8) Output A[x],max.

3. Code

4. Problems encountered during commissioning and solutions
    • The problem encountered:

      • Each loop A[i] is 10 and is not correctly assigned
    • Workaround: Assign A[i] to the correct value.

Topic 2:7-3 Year of birth 1. The results of PTA experiment

2. Design Ideas
    • (1) Char a[5];int i=0; Enter the value of A[i] separately by loop

    • (2) int n=1,kind;scanf (kind value);

    • (3) int age=0,sum=0;for (i=0;a[i]!= "; i++) {Converts a character to a number and becomes ' sum=sum*10+a[i]-' 0"

    • (4) int Ge,shi,bai,qian;

    • (5) while (N!=kind) {performs cyclic n=0;

    • (6) Calculation of individual digits

    • (7) If all are the same number, n=1, if there are 2 species, n=2, if three species, n=3, if 4 species, n=4

    • (8) age++;sum++ (if the kind value is not met, the next year is counted);} Until the condition is not met; the loop ends.

    • (9) N=3;sum--;while (n!=-1) {

    • a[n]=sum%10+ ' 0 '; sum=sum/10;n--; turning numbers into characters

    • (11) Output ("%d%c%c%c%c", age-1,a[0],a[1],a[2],a[3]);

3. Code


4. Problems encountered during commissioning and solutions
    • The problem encountered:

      • should not be in line with the output, and should have been equal to 3 of the but became 0;

      • There should be only 2 numbers, but 3 kinds of numbers are output. Should be n=3 when the condition is insufficient.

    • Workaround: Add n=0 to the while line. Plus conditions.

Topic 3:7-4 Simplified Insertion sort 1. The results of PTA experiment

2. Design Ideas
    • (1) define n,i=0; enter N;

    • (2) Define a[80]={0}

    • (3) for (i=0;i<n;i++) {input A[i] value

    • (4) Define X,J. Enter X value

    • (5) for (i=0;i<n;i++) {

    • (6) if a[0]>=x) {Execute loop for (j=n;j>0;j--) {a[j]=a[j-1]; otherwise a[0]=x; exit loop;

    • (7) if a[n-1]<=x) {a[n]=x; exit cycle;

    • (8) If a[i]<=x&&a[i+1]>=x executes loop for (j=n;j>i;j--) {a[j]=a[j-1]; a[i+1]=x exits the loop;

    • (9) if (n==0) a[n]=x;

    • (10) The value of output a[] respectively.

      3. Code

4. Problems encountered during commissioning and solutions
    • The problem encountered:

      • When N=0,x=1 is not output a "N" =1. and the output is a[n]=0.
    • Solution: Add a n=0 judgment.

Second, this week's topic set PTA Submission List and the final ranking. 1.PTA Submission List










2.PTA Rankings

Third, peer code peer review (1 points) 1. Mutual evaluation of the names of students

European Yang.

2. My code, peer-to-peer code (the core code here is good, not necessarily all the code, the figure indicates whose code.) )
    • It's mine:

    • He's:

3. Where do I differ from my classmates ' code? What are the advantages? What style of code do you prefer? If the classmate code is wrong, please help to point out where the problem.
    • He writes more easily than I do, and he determines whether the year meets the criteria by judging whether each number meets the criteria, and I use each condition list to output these answers.

    • Compared to his code to save time, this is where I should learn.

Iv. Study Summary of the Week 1. What did you learn? How do I store strings in 1.1 C?

To store with a character array or with a character pointer

1.2 What is the end flag of a string and why do you want to end the flag?

' + '; Let it automatically exit the array at the specified location without continuing execution.

1.3 What are the methods for string input?

scanf ("%s", &op) and gets (OP)

1.4 Numeric characters How to turn an integer, write a pseudo-code?

Defines a character op, which computes n=op-' 0 ';

1.5 16 binary, binary string how do I turn 10 binary? Write pseudo-code.
    • 16 binary: Define array a[100] Each character of the hexadecimal string is stored, AUM, if the character is a--z, then ' sum=sum16+a[i]-' a ' +10 '. If the character is A--z, ' sum=sum16+a[i]-' a ' + 10 ', if the character is 0--9, then ' sum=sum*16+a[i]-' 0 '

    • 2 binary: Define array a[100] Each character of the hexadecimal string is stored, AUM, if the character is a--z, then ' sum=sum2+a[i]-' a '. If the character is A--z, ' sum=sum2+a[i]-' A ', if the character is 0-- 9, then ' sum=sum*2+a[i]-' 0 "

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

When to use a numeric array, when to use a character array, especially when an array has numbers, always feel that the character array can be, but the last but not the correct answer; and the use of two-dimensional arrays; When a newline character is added, sometimes the array is changed before or after the input array is added with a newline character.

3. Midterm Summary 3.1 Why do you think you didn't do well?

The contents of the book are not carefully studied and understood. The examination attitude is not correct, oneself do not want to write not to write. Code reading ability is low, time distribution is uneven.

3.2 List the wrong questions.
    • 1.. The conditions of the do while are different and always assume that the parentheses are satisfied to exit the loop.

    • 2. Cannot use scanf (), should be used (ch = getchar ())

    • 3. Custom function The piece didn't look out.

    • 4n<1 conditions are not stated, and the program is too messy to read.

3.3 The second half semester how to adjust C's study?

Since there is a written test, you should go to read a book, the contents of the books to see, do not test the book's own not. The code in the book also has to go to see, so you can learn a lot of things. Correct study attitude, reasonable grasp of time, take the exam seriously. Improve your ability to read code. Practice your ability to write pseudo-code, now I can not even pseudo-code and write steps are not clear.

C Language Blog Job--one or two-dimensional array

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.