C language function 2

Source: Internet
Author: User

One, PTA experiment 6-3 Use the function to determine the total square number: 1. PTA Submission List:

2. Design ideas:

3. Problems encountered in debugging process and PTA Submission List situation Description:
    • 1. First consider the input value N to divide a loop variable i,i with the number of cycles change, N each time except two I, can get 1 value is the full square number, return 1 value, otherwise when the I>N/2 cycle ends, then return 0 value; At first, I thought it was feasible, But in fact, once run debugging found a lot of errors, and later found that because the 1 and 0 is not considered the particularity, but even if the consideration is still not right, in the classmate's suggestion with the converse idea even if I*i==n,return 1; and I value to make up N value; and now it's done again with the first thought, Trying to figure out what was wrong in the first place, but found it once, it was clear that the previous failure to understand when the called function once return will not execute the subsequent statements, so before considering a bunch of conditions, the more complex the more prone to error;
    • 2. This is the right answer that is now done with the first thought;
    • 3. But then there was a problem, and when the called function returned a value, the execution should not end immediately, why when I put the IF (n==0| | N==1) return 1, when the statement is placed outside the loop is right, and put it inside the loop is not correct, it seems to be an invalid statement???
    • 4. This picture is the IF (n==0| | N==1) return 1; statement placed in the loop, is wrong, do not know why??? Hope to have great God to help answer;
6-6 number of daffodils with function output: 1. PTA Submission List:

2. Design ideas:

3. Problems encountered in debugging process and PTA Submission List situation Description:
    • 1. This problem just started when the PTA prompt run time-out, the students suggest to optimize the algorithm, remove unnecessary steps, and then re-write again,
    • 2. This is the first time to write some complex code;
    • 3. This is the second optimized code, or display run timeout;
    • 4. Then re-wrote the code, this idea is much clearer than before, after the confidence to submit, the PTA answered my four words "part of the correct", the code for two days, a bit of a crash, and then ask classmates, students remind me that the number of times should be equal to the number of digits, perhaps because of inertia thinking, and not pay attention Thought that the number of daffodils is equal to the number of each digit after the three, and then added a step to calculate the integer number of algorithms, the answer or wrong, in the classmate tips found not to the statistics of the number of full-digit count value assigned to the initial values, to count the answer is correct after assigning an initial value;

      6-7 end of the specified range using the function output: 1. PTA Submission LIST:

      2. Design ideas:


3. Problems encountered in debugging process and PTA Submission List situation Description:
    • 1. At the beginning of examining a little confused, do not know what factor is, think as long as the number of its own can be addend, later Baidu only know the factor equivalent to approximate, and then began to do the problem;
    • 2. Debugging found that because I to meet the I<=NUMBER/2, so the number=1 value is always not into the loop, so another to 1 value set the execution steps;
    • 3. Debugging and found that Sample2 can not achieve the output, that is, when there is no completion of the situation in a range is not considered, the beginning can not find as the number of rely on conditions, and then a new set of the variable count, used to count the number of numbers, when the count==0 output no perfect number ;

      Second, peer code pairs of peer review: 1. The code of the classmate;

2. My Code;

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.
Third, this week's topic set PTA Final ranking:

Iv. Summary of this week's study: 1. What have you learned? 1. What data types are in C language?
    • 1. Integer variables and constants, floating-point variables and constants, character-type variables and constants;
2. Where do the character data need to be noted?
    • 1. ' A ' and ' a ' are different character-type constants;
    • 2. ' A ' +1 corresponds to the character ' B ';
    • 3. Lowercase letters to uppercase: ch=ch-' a ' + ' a ' or ch=ch-' B ' + ' B ' and so on, uppercase letters converted to lowercase: ch=ch+ ' a '-' a ';
    • 4. The lowercase letter is 32 more than the uppercase ASCLL code;
    • 5.getchar () and Putchar () can only handle input and output of a single character;
    • 6. The space and carriage return will be absorbed by%c;
    • 7. ' 1 ' of the ASCLL code is; ' A ' 's ASCLL code is 65;

      3. Self-increment decrement operator?
    • 1. Prefix + + +1 and then assignment, suffix + + is first assigned value and then +1;

      4. Operator precedence?
    • 2. The single-mesh operator, the combination of conditional and assignment operations, is placed right-to-left, arithmetic operations (binocular operators), shift operations, relational operations, bit-logical operations, and logical operations that are bound from left to right;

      5. Which expressions are in C language? What do you do wrong in class, please analyze the reason here?
    • 1. When the variable to the left of the assignment is not the same as the variable type on the right, calculate the value on the right and assign it to the left, and convert it to the left variable type;
    • 2.double 3 Get 3.0;int3.8 get 3;
    • 3. The difference between prefix + + (-) and suffix + + (-) is not very clear, prefix + + +1 is assigned, suffix + + is first assigned value and then +1;
    • 4. When a=3, the value of a+=a-=a*a is wrong, the reason is not aware that a is a variable, in the process from right to left, A is 9 when a is still calculated;
    • 5. Do not understand the value of the 8>6>3, that is, the principle of the relational operator is not clear, and then understand the monocular operator from left to right combination, first calculate 8>6, 1 (the result of the relational operator is not 1 is 0), it is obvious that 1>3 is not established, so the 0;

      6. Other content?
    • 1. XOR: The same is 0, the difference is 1;
    • 2. Take counter (bit non-operation): 0 becomes 1, 1 becomes 0;
    • 3. In contrast to the rule of bitwise "and" and XOR, the bitwise "and" is different from 0, the same as 1;

2. This week's content, you are not what?
    • 1. The use of escape characters is not very clear;

    • 2.ASCLL code corresponding to the character is not very clear;
    • 3. Conversion between conversions is not very clear;

      3. Circular Structure Test Summary (all students must write)
1. What is wrong with the question, and how to change it? 2. is the exam result satisfactory, how to improve? 3. Other summaries.

C language function 2

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.