C Language Fifth Blog job--function

Source: Internet
Author: User
Tags arithmetic operators define function logical operators

One, PTA laboratory work. 6-5 use the function to output an inverse number of an integer 1. The results of PTA experiment

2. Design Ideas
    • (1) The definition of five integer variable n,count,i,x,sum.
    • (2) assigns the initial value, assigns the number of the entry function to the n,sum=0,count=0.
    • (3) Count the number of digits of the input.
    • (4) n=n/10,count++.
    • (5) Repeat step 4 until n=0.
    • (6) I=count-1.
    • (7) The number of the remainder x,x=number%10.
    • (8) Calculate Sum=sum+x*pow (10,i).
    • (9) Calculate NUMBER=NUMBER/10.
    • (10) Repeat step 7 until i<0, ending the loop. Returns the value of sum to the main function.
3. Problems encountered in debugging process and PTA Submission List situation description.
    • There is no problem in the subject.
6-7 use the function to output the number of 1 in the specified range. PTA Experiment Results

2. Design Ideas
    • (1) the function factorsum (int number) is defined and the output is completed.
    • (2) The definition of two integer variable sum=1,i=2.
    • (3) If number%i==0, then sum=sum+i.
    • (4) i++.
    • (5) Repeat step 3 until i>=number, end the loop, and return the value of sum to the main function.
    • (6) Define function void Printpn (int m, int n)
    • (7) define three integer i=m,j=2,count=0.
    • (8) if factorsum (i) ==1, then count++,printf ("%d = 1", i).
    • (9) If i%j==0,printf ("+%d", j), printf ("\ n").
    • (Ten) J + +.
    • (11) Repeat step 9 until j>=i, ending the loop.
    • (i++).
    • (13) Repeat step 8 until i>n, ending the loop.
    • if (count==0) printf ("No Perfect Number").
3. Problems encountered in debugging process and PTA Submission List situation description.
    • (1) Output only one
    • Fix the problem: in the first function, change the i=1 to i=2 because any number pair 1 takes 0. and change the i<=number to I<number because the end number does not include itself. In the same vein, J of the second function is corrected.
    • (2) The output format is incorrect.
    • Workaround: Add a space.
7-1 number of combinations 1. PTA Experiment Results

2. Design Ideas
    • (1) Define four floating-point number x,y,m,n.
    • (2) Enter two floating-point number m,n.
    • (3) Call function Fact,y=fact (n-m), M=fact (M), N=fact (n).
    • (4) Calculate x=n/(y*m).
    • (5) Output x (do not retain decimals).
    • (6) Defining a function double fact (double b)
    • (7) Define two floating-point i,a=1.
    • (8) for (i=1;i<b;i++) a=a*i.
    • (9) Return the value of a to the main function.
3. Problems encountered in debugging process and PTA Submission List situation description.
    • (1) Not using%.0LF to make the answer wrong.
Second, peer code pairs of peer reviews. 1. Mutual evaluation of the names of students.

Lin Zhixu.

2. My Code, mutual evaluation of the student code.

6-8
My Code

int fib(int n){  int a,b,t,i;  a=b=1;  for(i=2;i<=n;i++){  t=a+b;  a=b;  b=t;  }   return a;}void PrintFN(int m,int n){   int i,j,count=0;   for(i=1;i<=10000;i++)   {    if(fib(i)>=m&&fib(i)<=n)    {       printf("%d",fib(i));       count++;       break;}   }       for(j=i+1;j<10000;j++){        if(fib(j)>=m&&fib(j)<=n)       printf(" %d",fib(j));       count++;}    if(count==0)    printf("No Fibonacci number\n");}

Forest Code

int fib( int n ){    int i,a,b,c;    a=b=1;    for(i=2;i<=n;i++){    c=a+b;     a=b;    b=c; }    return a;}void PrintFN( int m, int n ){    int j,flag=0,u;    if(m==1&&n==1)    printf("1 1");    else{    for(j=m;j<=n;j++){        for(u=1;u<=n;u++){        if(fib(u)>j)        break;        if(j==fib(u)){        flag=1;        printf("%d",fib(u));        if(fib(u+1)<=n)        printf(" ");}        }    }    }    if(flag==0&&m!=1&&n!=1)    printf("No Fibonacci number");}

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: the function void printfn (int m, int n) are treated differently.
    • Advantage: Lin's code skillfully use if to solve the last can not have a space problem, and the overall code is relatively concise and high readability. My code is more normal, step by step.
    • I prefer Lin's.
Third, this week's topic set PTA Final ranking.

Iv. Summary of the study this week. 1. What have you learned? What data types are 1.1 C languages?
    • Basic data types, such as: Integer, Long integer, short integer, unsigned integer, unsigned long, unsigned short, character, single-precision floating point, double-precision floating point.
1.2 Character type data need to be aware of the place?
    • Each character type data occupies one byte in memory.
    • The definitions and values of integer and char variables are interchangeable.
1.3 Self-increment decrement operator?
    • ++n is equivalent to N=n+1,--n.
    • ++n is the value that executes the n=n+1 first, and then the value of n as the expression ++n. n++, the value of n is first used as the value of the expression n++, and then the n++ is executed.
    • An operand can be a variable only, not a constant or an expression.
1.4 Operator Precedence?
    • Elementary Operators > Single-mesh Operators > Arithmetic operators > Shift operators > Relational operators > Bitwise logical operators > Logical operators > Three mesh Operators > Assignment operators > Comma operators
    • The monocular operator, the assignment operator, the trinocular operator, and the assignment operation are combined right-to-left.
1.5 which expressions are in C language? What do you do wrong in class, please analyze the reason here?
    • An assignment expression, a logical expression, a conditional expression, a relational expression.
    • No.
2. This week's content, you are not what?
    • The application of some special data types and operator precedence is not familiar enough.
3. Circular structure Examination Summary 1. What is wrong and how to change it?
    • 4th and 5th did not do it. In the fourth question did not understand the meaning of the topic, the processing of the conversion of a moment without understanding, resulting in stuck.
2. is the exam result satisfactory, how to improve?
    • Not satisfied. Consolidate the basics, practice more code, and improve the efficiency of the problem and the readability of the code.

C Language Fifth 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.