C Language Blog Job--function

Source: Internet
Author: User

One, PTA laboratory work. Topic 1:6-5 Use a function to output an inverse number of an integer 1. The results of PTA experiment

2. Design Ideas
    • (1) Define and assign integer variables within the reverse (int number) function Count=0,i,j,x,a,sum=0,number_copy=number

    • (2) When number!=0, the loop COUNT++;NUMBER=NUMBER/10 is executed, and the loop is exited until number=0.

    • (3) Assign the Number_copy value to number.

    • (4) When I<=count, perform cycle, I=1,X=NUMBER%10;A=X;SUM=SUM+A;NUMBER=NUMBER/10; i++; until I>count, exit the loop;

    • (5) in (4) loops nest a loop when the j<=count-i executes the loop, j=1,a=a*10;j++; until J>count-i, jump out of the loop

    • (6) returns SUM.

3. Problems encountered during commissioning and solutions
    • The problem encountered:

      • Ben should have number=1234 after a loop, and it turned 12340. The final answer turned into 0;

      • Debug to the end no matter what you enter, the display is 0, because when the previous loop ends, number=0 does not do any processing directly into the next loop, making the value 0

    • Workaround: Remove the number=number_copy, so that you can get rid of the value of single bits, so that the answer is correct; redefine a variable to fit the number before the change. The original value is then re-assigned to number after the last loop has ended.

Topic 2:6-6 using functions to output daffodils 1. The results of PTA experiment

2. Design Ideas
    • (1) Execute function narcissistic (int number), define integer variable sum=0,i,x,a;

    • (2) Assigning the value of number to a

    • (3) If number=10000, return 0 value

    • (4) If number/1000>=1, executes the loop, executes ' x=number%10;sum=sum+xxx*x;number=number/10;i++ ' when i<=4, and exits the loop until i>4.

    • (5) Otherwise, the loop is executed when i<=4 executes ' x=number%10;sum=sum+xxx;number=number/10;i++; ' Until the i>4 exits the loop.

    • (6) If sum=a, return 1. Otherwise return 0.

    • (7) Execute function printn (int m, int n);

    • (8) Define integer variable Sum,j,x,i,a.

    • (9) When j=m+1,j<n, perform cycle, a=j,sum=0;

    • (10) If the a=10000, do not perform the following operation directly to the next cycle;

    • (11) If a/1000>=1, executes the loop, when I<=4 executes ' x=a%10;sum=sum+xxx*x;a=a/10;i++; ' Until i>4 exits the loop.

    • (12) Otherwise, the execution cycle, when i<=4 execution ' x=a%10;sum=sum+xxx;a=a/10;i++; '
      Exits the loop until i>4.

    • (13) If sum=j, the value of the output J.

3. Problems encountered during commissioning and solutions
    • The problem encountered:

      • Should have started from 2, he would j=359 directly, and jump out of the loop

      • The final answer is no, and when j=370,sum is not equal to the 370 already defined, and only 25, x^3
        cannot be used for calculations

    • Workaround: Change j=359 to j=m+1; change x^3 to ' x xx '.

Topic 3:7-1 Number of combinations 1. PTA Experiment Results

2. Design Ideas
    • (1) Executes the main function int main (void). Defines two integer variable m,n. Floating-point variable result.

    • (2) Enter a value of two variables M,n.

    • (3) Calculate ' Result=fact (n)1.0/(Fact (m)fact (n-m)); '

    • (4) Output printf ("result =%.0f", result), reserved integer.

    • (5) Executing the fact (int n) function on the basis of the main function;

    • (6) Define the integer variable i in the Custom function, the floating-point variable result_fact, and assign a value of 1;

    • (7) When I=1,i<=n executes the loop, calculates ' result_fact=result_fact*i ' until the i>n ends the loop.

-(8) Return result_fact value

3. Problems encountered during commissioning and solutions
    • The problem encountered:

      • [] above is the answer error, but I brought a number of values, are correct, according to my estimation should be a value brought in, resulting in an integral type and floating point type has a difference.
    • Workaround: Define result_fact as a floating-point variable

Second, peer Code peer review (2 points) 1. Mutual evaluation of the names of students.
    • Tri Zhibin
2. My Code, mutual evaluation of the student code.
    • 6-5

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.
    • 6.5

      • The variables are different; I use the first figure, and then use the number of digits to calculate the number of reverse, he is the output ' single digit *10 ' + bits and then a similar cycle;

      • His code is simpler, only one loop structure is used, and a comment is added; my relative complexity to him, no technical method, more suitable for people like me

      • His simple method is worthy of my study, the technical way of thinking is also worthy of my study, but also learn to use annotations to make the code more understandable.

Third, the PTA submission list and the final ranking of this week's topic set. 1.PTA Submission List










2.PTA Rankings

Iv. Study Summary of the Week 1. What did you learn? What data types are 1.1 C languages?

Integer (Int,long[int],short[int],unsigned[int], etc.), character type (char), float (float and double)

1.2 Character type data need to be aware of the place?
    • (1) Use%c when scanf input.

    • (2) Add "when assigning value.

1.3 Self-increment decrement operator?

--Self-reduction, + + self-increment. ++n is the first assignment in the operation, n++ is the first operation in the assignment.

1.4 Operator Precedence?

! --++,--,+,-,(monocular)-- /%--+---<, <=,>,>=--==,! =--&&,| | ——? :--=,+=,-=,*=,/=,%=--, from high to low, executed from left to right

1.5 which expressions are in C language? What do you do wrong in class, please analyze the reason here?
    • Assignment expressions, relational expressions, relational expressions, logical expressions, conditional expressions

    • For the division of integer variables, such as the sixth question in class, X=10/4, I counted him as the usual arithmetic format, just X is floating point, so I wrote it wrong.

1.6 Other content?

The use of functions in programming can make the calculation easier.

2. This week's content, you are not what?

The place in the data structure about the order of expression operations is not very understanding. There is also the combination of two custom functions or not understand, mainly the next part of the custom function can be represented by the previous custom function, but you do not represent, there is the conversion of character variables and numeric variables or not how. Sometimes it's confusing.

3. Circular Structure Test Summary (all students have to write) 1. What is wrong and how to change it?

7-5 word length. Instead, it's right. Because the previous code will output 1 "" Instead of 1 when only one word is entered.

2. is the exam result satisfactory, how to improve?

Not satisfied, earnestly completed the teacher's homework and PTA, so that each topic to do their own, they can solve.

3. Other summaries.

Some topics know what is wrong, but Dev does not debug, format error regardless of how to lose, the answer is the same as the example. I can't see it.

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.