C Language Blog Job--function

Source: Internet
Author: User
Tags decimal to binary goto

First, the PTA Laboratory work Topic 1: Use the function output Narcissus number 1. PTA Submission List

2. Design Ideas
    • int narcissistic (int number) function
      • 1. Define integer variable int i,j,m;
        int n,digit=0,n1,n2;
        int num,re_number=0;
      • 2. Allow N1,N2 to assign the value of number n1=number; N2=number;
      • 3.for Loop {n=n1%10;
        digit++;
        N1=N1/10;} The number of digits used to count numbers
      • 4.for Loop {num=1;
        n=n2%10;
        N2=N2/10;
        Embedded layer for loop {num=n*num;}
        Calculates and re_number=num+re_number of each digit;
        }
      • 5. Determine if the re-formed number re_number is equal to numbers, or 1 if equal, or 0 if it is returned.
    • void Printn (int m, int n) function
      • 1. Define integer variable M
      • 2. Use the For loop increment (m=m+1; m<n; m++), which also refers to the function narcissistic (int number) to determine if M is a daffodil, and if so, the output m.
3. Problems encountered in debugging process and PTA Submission List situation description.
    • Problem: Ignoring the requirement of another function is "to print out the number of daffodils in a given interval (m,n) in order from small to large," and to make a judgment on N more.

    • Workaround: Change "m<=n" to "M<n"
Topic 2: Use a function to output the number of Fibonacci within a specified range of 1. PTA Submission List

2. Design Ideas
    • int fib (int n) function
      • 1. Define integer variable i,f1=1,f2=1,f3; I used to control the cycle, F1,F2,F3 used to calculate Fibonacci number
      • 2.for Loop (i=3;i<=n;i++) {f3=f1+f2;
        F1=F2;
        F2=F3;}
      • 3. Return to F2.
    • void printfn (int m, int n) function
      • 1. Define integer variable j,i,flag=0,sign=0;
      • 2. Define integer variables time=0;//to calculate the number of Fibonacci in a given range of topics;
      • 3. First for Loop (J=1;fib (j) <=10000;j++) {time + +;}
      • 4. Second heavy for loop (i=1;i<=time;i++) {
        if (fib (i) >=m&&fib (i) <=n)
        {if sign==1 then output spaces;
        flag=1; The value of the output fib (i);
        Sign=1;}
      • 5. If flag==0 then output "No Fibonacci number".
3. Problems encountered in debugging process and PTA Submission List situation description.
    • Problem: The second function misses the case of Fibonacci number 1, 1 is Fibonacci, but the result is "No Fibonacci number".

    • Workaround: Rewrite the code, the second function calculates the number of Fibonacci within the limit of the topic, and then uses the Loop statement to find out all Fibonacci in [M,n] based on the number of Fibonacci.

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

2. Design Ideas
    • 1. Define integer variable M,n;
    • 2. Enter M,n;
    • 3. Output result ("result =%.0LF", reference function fact (n)/(Fact (M) *fact (n-m));
    • 4. Defining a function double fact (int n)
      • 5. Define the floating-point variable product, define the integer variable i;
      • 6. Assign the initial value of product to 1;
      • 7.for Loop (i=2;i<=n;i++) {product *= I;}//Count factorial
      • 8. Returns the value of product.
3. Problems encountered in debugging process and PTA Submission List situation description.

There is no difficulty in the subject, define a function to calculate the factorial, the main function reference three times the function can calculate the result.

Second, peer code Peer review 1. Peer-to-peer reviews photos of me and Li Mengbin classmates

2. My Code, peer code Li Mengbin classmate'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: In the final output section using Goto directly out of all loops, although convenient and quick, but I personally think some opportunistic, goto or try to use less.
    • Dream Ice code: Dream Ice of the first custom function, the judgment of the prime number, in fact, in the p%2==0 can exit the cycle, but the dream ice is always p do to the I of the rest operation; The code for the second custom function is simpler and more efficient than mine, and I used two if judgments and two for loop statements to make the code look verbose.
    • In conclusion, I like the code of the Dream ice more.
Third, this week's topic set PTA Final ranking.

Iv. Study Summary of the Week 1. What did you learn? What data types are 1.1 C languages?
    • Integral type, character type, real type.
1.2 Character type data need to be aware of the place?
    • 1) The definition and value of the character type integer variable and the character type variable can be exchanged with each other;
    • 2) When exchanging the definitions and values of integer and character variables, the value range of integer data is valid ASCII code;
    • 3) The capitalization of the letters is different from the character type constants.
1.3 Self-increment decrement operator?
    • 1) set n is an integer variable and has been assigned, then n++ and ++n are equivalent to n=n+1, except that ++n represents the value of n plus one, and n++ still represents the value of the original n, but then n is equal to the value of "n+1". n--and--n.
    • 2) The operand of the self-increment decrement operator can only be a variable, not a variable or an expression.
1.4 Operator Precedence?
    • 1) If the operators on both sides of the operands have the same precedence, the calculation order is determined by the binding;
    • 2) You can use parentheses to change the order in which operators are executed.
1.5 which expressions are in C language? What do you do wrong in class, please analyze the reason here?
    • 1) Arithmetic expressions, assignment expressions, relational expressions, logical expressions, conditional expressions, comma expressions.
      • The form of the conditional expression: expression 1? Expression 2: Expression 3.
      • The general form of a comma expression: expression 1, expression 2, ..., expression n
        Each expression is evaluated sequentially, and finally the value of expression n is used as the value of the symbol expression, and the type of the expression n is the type of the comma expression.
    • 2) class assignment sixth, forget that 10 and 4 are integral constants, although X is floating point, but the result of 10/4 is an integral type, and it becomes floating point when assigning x value.
    • 3) class assignment Nineth, the increment symbol in the back of the operation and in the previous operation is not the same, J + + should still be the result of 3.
1.6 Other content?
    • The octal, hexadecimal representation of integers in the C language.
    • The automatic conversion of data type follows certain rules, in the assignment operation, the type of the data on both sides of the assignment number is best, at least the right data type is lower than the type level of the left data, or the value of the right data is within the value range of the left variable, otherwise it will result in lower precision and result error.
    • The casting of the data type, the general form is (type name) expression, the type conversion is only for the needs of this operation, the temporary conversion of the data type, and does not change the definition of the data.
2. This week's content, you are not what?
    • The bitwise operation is not well understood;
    • The conversion to octal and Hex is also not very understanding.
3. Circular Structure Exam Summary 3.1 which problem is wrong, how to change?
    • 1.7-32 The leading 0 of the binary
      • Forget the decimal to binary system How to calculate, later tangled in the calculation of the result is a binary number in reverse order.
      • Ask the classmate, the study found that even if the result is a binary inverse number, but the number of bits is the same and the binary number in addition to 0, the first bit must be 1, then this as the condition can calculate the number of binary digits, and then subtract from 32, the number of leading 0.
    • 2.7-5 Word length
      • It is not output correctly when you enter an empty statement and multiple spaces, but it is not yet resolved.
3.2 Exam results satisfactory, how to improve?
不满意,对嵌套循环的是用还是不太熟练,而且这次考试的状态不太好,看到题目时脑子一片空白,注意力不集中,或许是平常做题花的时间太长,以后做题时会更加专注,在读题解题方面也需要加强。
3.3 Other summaries.
    • Decimal to binary is to keep the decimal number in addition to the second surplus until divided by two equals 1 o'clock stop;
    • The inner loop condition of most nested loop statements depends on the condition of the outer loop. "But always forget"

C Language Blog Job--function

Related Article

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.