C Language Blog Job--function

Source: Internet
Author: User

First, the PTA experimental work Title 1:6-4 400~499 in 4 occurrences of the number of 1. PTA Submission List

2. Design Ideas
  • The first step: the Custom function int fun (int x), the function name is fun (), the return value is integer type, the input value is integer type;
  • The second step: Define the variable count to represent 4 of the number, Ge,shi,bai, respectively, single-digit, 10-digit, hundred number;
  • Step three: bai=x/100;shi=x/10%10;ge=x%10;
  • Fourth step: If bai=4,count++, if shi=4,count++, if ge=4,count++;
  • Fifth step: Returns the result count.

    3. Problems encountered in commissioning process and PTA submission List status note
  • Problem: The number on the top of each position should be shi=number/10%10; forget to return the result, resulting in a wrong answer;

  • Workaround: Use the scanf statement to enter a numeric value, and then use debugging to find the 10-bit numerical calculation error, the return value is purely negligence, plus the return value to get the correct answer.

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

    2. Design Ideas

  • The first step: the Custom function int factorsum (int number), the functions name Factorsum (), the return value is the integer type, the input data number is the integer type;
  • The second step: define the variable i,total=0;
  • Step three: If number==1, return the result is 1; otherwise enter the loop for (i=1;i<number;i++);
  • Fourth step: if Number%i==0,total=total+i;
  • Fifth step: Repeat 3, 4, until I=number, if total==number after the end of the loop, return total;
  • Sixth step: The Custom function void printpn (int m, int n), the function name is PRINTPN (), the function has no return value, the input m,n is the integer type;
  • Seventh Step: Define the variable i,j,r,sum=0,flag=0,
  • Eighth Step: If m==1;printf ("%d =%d\n", m,m), flag=1;
  • Nineth Step: Otherwise Enter the loop for (i=m;i<=n;i++) if Factorsum (i) ==i,sum=0; Flag=1, and enter the sub-loop for (j=1;j<i;j++) if i%j==0,sum=sum+j;
  • Tenth step: Repeat step nine until the condition is not established;
  • 11th Step: If sum==i,printf ("%d =", i), and outputs the first factor 1, enter the loop for (r=2;r<i;r++), if i%r==0,printf ("+%d", r), and output a newline character after the end of the loop;
  • 12th step: If flag==0, output no perfect number.

    3. Problems encountered in commissioning process and PTA submission List status note
  • The return value in the first factorsum () function is mistaken, resulting in a return of only 1 or 0;

  • When i=28, the loop to the sum=28, that is, Sum=i did not jump out of the execution if (sum==i) statement, after debugging, after each cycle did not assign the sum value of 0, resulting in the next calculation error, resulting in the wrong result;

  • When the number of inputs is not considered in the empty set, resulting in the result is not completely correct, then added a flag variable, the flag initial value is 0, if the output data is feasible, flag=1, otherwise flag=0, when flag=0 is the empty set.

    The topic 3:7-1 the combination number 1. PTA Submission List

    2. Design Ideas Main function:

  • First step: Define integer variable m,n, floating-point variable C;
  • Step two: Enter M,n;
  • Step Three: C=fact (n)/(Fact (M) *fact (n-m));
  • Fourth step: Output C;

    Custom functions:
  • First step: Define the function double fact (int n), function name fact (), return value is double type, input n is integer type;
  • The second step: Define floating-point variable i=1,result=1;
  • Step three: Enter the loop for (i=1;i<=n;i++)
  • Fourth step: result=result*i;
  • Fifth step: Repeat step three or four;
  • Returns the result value.

    3. Problems encountered in commissioning process and PTA submission List status note
  • At first, the variables I and result in the definition function are defined as integral types, resulting in the correct part of the result;
  • The result of the final output without decimals, I originally defined C as a double type, in the output with "%f", resulting in the wrong answer, should use "%.0f";

    Second, peer code pairs of peer review 2. My Code, mutual evaluation of student code

    It's mine:
    Li Mengbin'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
  • The difference: I calculate it directly, 10, hundred of the number, and then judge whether they are equal to 4, and the Dream Ice code with a while loop, the loop once to judge;
  • Pros and Cons: Her code is more concise, and the code is small, can execute a wide range of numbers, and my code is only limited to three digits, the code is large, low efficiency, more suitable for people with less flexibility in the brain.

    Third, this week's topic set PTA Final Ranking

    Iv. Study Summary of the Week 1. What did you learn?

  • There are three basic data types for the C language: integer, real, and character. Integral type, including short, int, long, etc., real, floating point type, including float, double, etc., character type, char type, used to denote various characters, corresponding to ASCII code table one by one;
  • Enter character data with no spaces or other partitions, as the carriage return and other symbols are entered as variables;
  • Self-decrement symbols, such as i++,++i,i--,--i, note whether the prefix or suffix, I since the increment of the value is i+1, the value of the self-reduction is i-1, and the value of the expression i++ is the original value, the value of ++i is the self-increment value, the expression of the self-subtraction is similar to the same;
  • In class, there is a problem of self-increment, the reason is to ignore each increment, the value of the variable will change, rather than the original value;
  • Learned to solve some problems with the function.

    2. This week's content, you are not what?
  • The precedence of the operators is not too familiar, and the results of some large-channeling expressions are faint and often error-prone.
  • For some of the characters of the programming problem is not, for example, the last question of the upper test;
  • The application of three types of data is not well understood, especially short and long;
  • function problem, to those logical strong topic still do not understand, algorithm is not very clear.

    3. Circular structure Examination Summary 1. What is wrong and how to change it?
  • The third problem is wrong, the reason is that I will judge it is a prime if the statement placed in the loop inside, resulting in each number will be output, and the correct practice is placed in the loop outside, because, to all the numbers are judged to determine whether it is not a prime; here's my original code and the corrected code.

  • The fourth question because of the number of binary system is unfamiliar, and time is not enough so did not do;
  • The fifth problem output error, part of the correct, hint at the beginning of the end of a lot of space, until now have not corrected, here is my Code

    2. is the exam result satisfactory, how to improve?
  • Dissatisfaction, my goal is to pass, because last time on the machine test I failed, but I am sorry I did not pass this time, the last time I summed up the conclusion is to spend too little time, and then spend more time in the near stage, the effect is not obvious, so I have to reflect on their own learning methods have problems, So I'm not going to define this as a failure, but to define it as a fail, so I think I should find a way to learn for myself, not to spend as much time as others, but not to have the same effect as others.

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.