C Language Blog Job--function

Source: Internet
Author: User
Tags two factor

First, the PTA experimental work problem 1:400~499 4 occurrences of the number of 1. PTA Submission List

2. Design Ideas
    • 1. Define the integer variable J as the number of cycles, number 4
    • 2. The number is assigned an initial value of 0, with a for loop
    • 3. If x%10==4, make number plus a
    • 4. Calculate X=X/10, change the value of X
    • 5. Repeat steps 3,4 until j>3 end loop
    • 6. Return number to main function

      3. Problems encountered in commissioning process and PTA submission List status note
    • Error code




      Think that return 1 can be implemented multiple times, but when debugging see i=403, K is 4,i=404, K is 5 return to the main function, not k=6, so found the error.

Topic 2: Use the function to output the number of 1 in the specified range. PTA Submission List


2. Design ideas int factorsum (int number) function
    • 1. Define the integer variable I as the number of cycles, n for the remainder, the sum factor, the initial value of 0
    • 2. If number equals 1, return 1 directly; otherwise enter for loop
    • 3. Calculate n=number%i, if n equals 0, calculate sum=sum+i
    • 4. Repeat step 3 until the I>NUMBER/2
    • 5. If number equals sum, returns return sum

      void Printpn (int m, int n) function
    • 1. Define the integer variable j,k as the number of cycles, count for the remainder of the initial value of 1,flag assigned to the initial value of 0
    • 2. If M equals 1, Output 1 = 1 and then wrap
    • 3. Otherwise enter the double for loop, J=m starts and flag=0
    • 4. Call the Factorsum (j) function, and if the function value is =j, the output j=
    • 5. Enter the inner for loop, calculate count=j%k and flag plus a
    • 6. If count=0 and flag=1, Output K, if count=0 and flag is not equal to 1, output +k, if count=0 and K equals J/2, output line break
    • 7. Inner Loop Repeat step 5,6 until K is greater than J/2 end
    • 8. Outer loop Repeat step 3,4,5,6,7 until J is greater than n
    • 9. If count==1&&m!=1&&n!=1, output no perfect number

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



      From the first picture, we can see that there are two factor 1, the condition of the second picture frame solves the problem, because the original flag equals 1 o'clock will satisfy the first two if




      If the final condition is count! =0 will result in multiple output no perfect number, the final condition should be changed

Topic 3: Finding the number of combinations 1. PTA Submission List

2. Design Ideas Main function
    • 1. Define integer variable m,n, floating-point variable a,b,c,resuit
    • 2. Enter M,n
    • 3. Call the fact () function a=fact (m); B=fact (n); c=fact (N-M);
    • 4. Calculation result=b/(A*C)
    • 5. Output result

      double fact (int n) function
    • 1. Define integer variable i, floating-point variable sum is 1.0
    • 2. Calculate Sum=sum*i
    • 3. Repeat step 3 until I is greater than n end
    • 4.return sum to main function

      3. Problems encountered in commissioning process and PTA submission List status note
    • 1. The first answer error is that no initial value is assigned to sum
    • 2. The second answer error is that the result of the output is not an integral type

      Second, peer code pairs of peer review 1. Peer Reviews Photos

      2. My Code, mutual evaluation of the student code

    • Huang Guangqui's Code
    • 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.

      My code uses the formula for the topic, and another formula that Huang uses, such as C2 5= (54)/(21)
      and his code function name and variable name get not very understand, there are resultblow=itemI,item has been 1, not very understand why he had to fill in an item, and the following formula is the same situation, is not the brain show tease.
      I think my code readability can also be able to let people who read the code know what to do, Huang classmate's code I do not know what to do at first, think for a while to know what method he used.

      Third, this week's topic set PTA Final Ranking

Iv. Study Summary of the Week 1. What did you learn?
    • 1.1
      Three basic data types for C: integer, character, real
      The integral type has the symbol and the unsigned point, each has the integral type, the short integer type, the long integer type three kinds
      Real types include single-precision floating-point, double-precision floating-point
    • 1.2
      Character types have numeric characteristics, escape characters should be noted
    • 1.3
      The self-increment decrement operator has two functions: to increase the value of a variable by 1 or minus 1, and to take the value of a variable as the value of an expression
      But ++n and n++ have a very big difference: ++n is the first after the Fu, n++ is the first FU after the calculation
    • 1.4
      Logic! "Arithmetic" relationship "logic &&,| | "Conditions" assignment "comma"
    • 1.5
      Arithmetic expression assignment expression relationship expression logical expression conditional expression comma-expression
2. This week's content, you are not what?
    • 1. The conversion of character data and integer data is not very skilled
    • 2. The binary format is not clear
    • 3. Digital character to Digital
    • 4.++n and n++ are sometimes confused.
    • 5. For long expressions, precedence and bonding can be confusing
    • 6. The knowledge of bit arithmetic is unclear
3. Circular structure Test
    • 1. The final question did not have a full score, then the test is used for the loop, for some requirements can not be satisfied.
      After the exam to see the code after the students know that the problem can not be used for the loop, to use while loop to solve the problem.
    • 2. Can also, before the exam oneself think of the cycle of the poor, but actually the first four questions can be done in the test time, there may be these types I happen to.
      For the machine test is still some fear, the reason must be their usual knowledge points and the content of the textbook is not mastered thoroughly, only hope that the content of the textbook into the process of playing code, so that the full use of knowledge, so that their proficiency up.

C Language Blog Job--function

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.