C Language Blog Job--function

Source: Internet
Author: User
Tags define function

First, the PTA experimental work 1:7-1 to find the number of combinations 1. PTA Submission List

2. Design Ideas

factorial function Design ideas:

    • First step: Define the function type double type
    • Step two: Define two shaping variables i,n,i to calculate factorial, n is a function variable, define a floating-point variable sum to hold the factorial
    • Step Three: I=1,sum=1
    • Fourth Step: Sum=sum*i
    • Fifth Step: i++
    • Sixth step: Repeat the third step until I>n
    • Seventh Step: Return the value of sum

Main function Design idea:

    • The first step: Define two Shaping variables m,n, define a floating-point variable result holding combination number results
    • Step Two: Enter M,n
    • Step Three: Call function calculation result=fact (n)/(Fact (M) *fact (N-M))
    • Fourth step: Output result

Flow chart:

3. Problems encountered in commissioning process and PTA submission List status note
    • Problem encountered: The defined factorial function is double, but the type of the return value is defined as shaping, resulting in the correct part of the answer
    • WORKAROUND: Change int sun to double sum
Topic 2:6-6 using functions to output Daffodils number 1. PTA Submission List

2. Design Ideas

Determine the number of daffodils function (narcissistic ()):

    • The first step: Define the function type as shaping, the variable is the shaping variable number
    • The second step: Define the shape variable left to hold the remainder of number to 10, integer variable count holds numbers, sum shape variable holds each digit of the sum of the second side, shaping variable n,m for storing number
    • Step Three: Assign a value N=number,m=number
    • Fourth step: Calculate N=N/10,
    • Fifth Step: count++
    • Sixth step: Repeat step Fourth until n==0 (third to sixth steps to calculate number of digits)
    • Seventh step: Calculate left=m%10
    • Eighth Step: Sum=sum+pow (Left,count),
    • Nineth Step: NUMBER=NUMBER/10
    • Tenth step: Repeat the seventh step until m==0
    • 11th Step: Determine if sum is equal to number, if equal, return 1, otherwise return 0

Output Daffodil number function (PRINTN ()):

    • The first step: define function as shaping, variable is two shaping variable m,n
    • Step two: Define the shaping variables i=m+1
    • The third step: call to determine the number of daffodils function, determine if narcissistic (i) is equal to 1, if the output I
    • Fourth Step: i++
    • Fifth step: Repeat the third step until I>=n

Flow chart:

3. Problems encountered in commissioning process and PTA submission List status note
    • Problems encountered: The topic only requires the number of daffodils in the output interval, excluding the endpoint, judging the condition error, resulting in if the end of the Narcissus number is also output

      For example at this time should not output 371 for Narcissus number:

    • Solution: Carefully read the topic after the discovery is open interval (m,n), thus the cyclic judging condition i<=n changed to I<n

Topic 3:6-9 using functions to validate Goldbach conjecture 1. PTA Submission List

2. Design Ideas

Flow chart:

3. Problems encountered in commissioning process and PTA submission List status note
    • Problems encountered: Did not take into account that 1 is not a prime, should be returned 0, and the judgment number of the loop does not have 1, so when input 1 o'clock no return value

    • Workaround: Add if (p==1) return 0 before the loop;

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

2. My Code, mutual evaluation of the student code

My Code:

Zhu Jiewei Student 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.
    • Different points and their respective advantages: My code in the calculation of the sum of the number of daffodils with the loop structure will be each of the power operation after the accumulation, and Zhu classmate's code directly to each of the numbers are calculated directly Add. But Zhu's code can only calculate the number of daffodils within 10000, and I can calculate more bits
    • More like the code style: relative to the subject more like their own code, Zhu classmate's code is not annotated, look at people do not understand
Third, this week's topic set PTA Final Ranking

Iv. Study Summary of the Week 1. What did you learn?
    • Through this week's study I understand the difference between global variables and local variables and the pros and cons of global variables.
    • This week I learned about data types, and I learnt how to use scientific notation to represent a number, and the most impressive thing about this week's course was the difference between a++ and ++a, and the value of the two expressions.
    • Also learned the precedence of operators in a complex expression and their order of operations.
    • This week, the main error points and note: PTA in the specific output format of the space is not considered in place, for example, 6-8 using the function output the number of Fibonacci in the specified range and 6-7 using the function output in the specified range of the end of the two questions and the last question of the machine exam this week, The three problems of the algorithm design is not difficult, but the problem of fixed output format led to a lot to consider, and sometimes consider one of the special points when you will ignore the other, and do it after looking back to see a lot of them can be deleted, the main reason or the idea of the algorithm is not good enough, Think carefully when you write later.
What data types are 1.1 C languages?
    • Integer type, character type, floating point type.
1.2 Character type data need to be aware of the place?
    • The character constants need to be ", ' 0 ' and 0, ' 0 ' for the character type, and 0 for shaping.
1.3 Self-increment decrement operator?
    • ++;--
1.4 Operator Precedence?

Monocular operator precedence is higher than binocular operator precedence.
Monocular Operator Precedence:

    • 1:[], ()
    • 2:--, + +,! , &, | , ~, sizeof
    • 3:/, *,%
    • 4:+,-
    • 5:>>, <<
    • 6:>, >=, <, <=
    • 7:==,! =
    • 8:&
    • 9:^
    • 10:|
    • 11:&&
    • 12:| |
    • 13:?:
    • 14:=, + =,-=, *=,/=,%=,
1.5 which expressions are in C language? What do you do wrong in class, please analyze the reason here?
    • arithmetic expressions, assignment expressions, relational expressions, logical expressions, comma expressions, bitwise operations.
1.6 Other content?
    • Length operator sizeof
2. This week's content, you are not what?
    • For the contents of this week's data structure, for bit arithmetic is still not quite clear, confuse bit operator, for a complex bit operation expression always need to read to do not mistake each operator.
    • The use of static is not too well understood, perhaps because it is not used in code, not very familiar.
3. Circular Structure Examination Summary

The following questions exist in this exam:

    • Read the question not carefully enough. Do not understand the topic clearly, this problem appears in the third question, for the topic Understanding error, the topic requires output is not greater than the number of 10 primes, the input number range is (50,20000), when input 51 o'clock should output less than 51 is greater than 0 10 primes, and I understand that the output is less than 51 greater than 50 of the prime, Cause the answer is always wrong.
    • The thinking is not clear. Test for the last question of the output format has not been clear, for the output of the situation is always absent-minded, may also be a bit impatient, at that time should be calm down to carefully analyze, clear thinking writing algorithm.

To this examination can not say very satisfied, because could have done better but did not do, the next exam to be more careful, in the next exam before the time I want to strengthen the design thinking this aspect.

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.