C Language Blog Job--function

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

One, the PTA laboratory work title One: 6-6 use the function to output the number of daffodils 1. PTA Submission List


2. Design Ideas
    • 1 define function narcissistic (int number)
    • 2 Defining local Variables Sum=0,n=number,end
    • 3 when number is three digits
    • 4 If the number/10!=0 enters the loop 5
    • 5end=number%10,sum=pow (end,3) +SUM,NUMBER=NUMBER/10
    • 6 Sum=pow (number,3) of the remaining number value for the highest bit that does not meet the cyclic condition +sum
    • 7 when number is four digits
    • 8 If the number/10!=0 enters the Loop 9
    • 9end=number%10,sum=pow (end,4) +SUM,NUMBER=NUMBER/10
    • 10 Sum=pow (number,4) of the remaining number value for the highest bit that does not meet the cyclic condition +sum
    • 11 If sum=n, return 1, otherwise 0

    • 1 define function void Printn (int m, int n)
    • 2 Defining local Variables I
    • The 3i=m+1;i<n,i++ loop calls the above function to determine if the number of daffodils is met, and the output
3. Problems encountered during debugging and PTA submission List situation Note When you start editing, you forget the change of number, resulting in the last sum and number no comparability, error

After correction found that the output of the data does not have 370, after debugging found their condition so that it does not enter the loop


Correct output after correction, but put on the PTA answer error, self-debugging according to the prompts to find their own data output has limitations

After adjusting the train of thought, re-modify the post-writing section correctly

After found himself test instructions did not understand well, when number four digits to four times, modify the correct problem after adding two: 6-7 use the function output in the specified range of the end of 1. PTA Submission List


2. Design Ideas
    • 1 define function factorsum (int number)
    • 2 Defining local Variables J.sum=0
    • 3 return 1 when number=1
    • 4j=1;j<=number/2;j++ Cycle 5
    • 5 if number%j==0, then sum=sum+j
    • 6 returns the value of the final sum

    • 1 define function void Printpn (int m, int n)
    • 2 Defining local Variables K,j
    • 3k=m;k<=n;k++, cyclic 4,5,6
    • 4 if K==factorsum (k), output "k =", when k=1 direct re-output "1"
    • 5j=1;j<=k/2;j++, Loop 6
    • 6 if k%j==0, Output "J", when J<K/2 output "+"
    • 7 end of each cycle output "\ n"
    • 8 if j==1&&m!=1, output no perfect number
3. Problems encountered in commissioning process and PTA submission List status note

The found output does not wrap, more output of no is not satisfied with the part

The output feels the same after adjustment

PTA part correct, debugging changes found themselves test instructions understand enough, continue to modify

PTA Display Format Error

Debugging found themselves more space, correct the problem after three: 7-1 to find the number of combinations 1. PTA Submission List

2. Design Ideas
    • 1 defining integer variable m,n, floating-point variable result
    • 2 Enter the value of the M,n
    • 3 Calling function Result=fact (n)/(Fact (M) *fact (N-M))
    • 4 output value of result

    • 1 Defining a function fact (int n)
    • 2 defining integer variable i floating-point variable product=1
    • 3i=1;i<=n;i++ Cycle 4
    • 4 product=product*i;
    • 5 returns the value of product
3. Problems encountered in commissioning process and PTA submission List status note


First write after the submission found part of the correct, for the wrong point to consider the situation of M=N/2 not quite understand, I changed some unnecessary places, and finally found that because of their definition of product is the problem of integer, when the number of factorial books is too large is not correct two, the classmate code peer review of 1. Peer reviews


2. Code for my Code, peer-to-peer code Lienzen

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 also please help to point out where the problem (1) My idea is to use a single-digit method, the first to calculate the number of digits, and then use the number of digits in a few times 10 of a certain time into the high order, and finally consider the last 0 of the problem (2) Lienzen of the idea is also useful to take But she is more ingenious use of the cycle, k=k*10+m the number of the original digit followed by the loop up high, output reverse order (3) My code is easier to think and start, easy to understand, but very cumbersome, not applicable, Lienzen code is relatively concise, usage is also very clever, but also avoid some hypothesis discussion, At the same time in the same circular statement to achieve their desired effect, concise and clear. (4) I like Lienzen's code style. 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
    • Signed: int; short[int] (range [ -32768,32767]); long[int]
    • Unsigned (natural number): unsigned[int];unsigned short [int] (range [0.65535]); unsigned long [int]
Character type
    • Char
    • You can use integers to represent characters ch= ' A ' equivalent to ch=65
Real type
    • Float (valid digital 7~8 bit)
    • Double (valid general 15~16)
    • Numerical accuracy and range of values are two different concepts
Real-type constants
    • Floating point notation (fractional form of real numbers)

      Must have a decimal point
    • Scientific counting method (exponential form of real numbers)

      E previous data, E after integer

1.2 Character type data need to be aware of the place?

    • ' A ' and ' a ', 0 and ' 0 ' are different
    • The definitions and values of integer and character variables can be exchanged with each other

1.3 Self-increment decrement operator?

    • The order of operations for ++n is: Execute n=n+1 First, and the value of n as the value of the expression ++n
    • n++ The Order of operations is: first the value of n as the value of the expression n++, in the execution n=n+1
    • An operand of a self-increment decrement operator can be a variable only, not a constant or an expression. 3++ or + + (I+J) illegal

1.4 Operator Precedence?

    • Assignment operators, conditional expressions, and! , single-purpose arithmetic operators are right-associative
    • Arithmetic operator and relational operator for binocular, logical operator and comma operator are left associative

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, conditional expressions, comma expressions



      I think I counted a a=9,a=a-a=3-9,a=a+a=3-6 when I counted.
      The actual should be a
      a=9,a=a-a=3-9,a=a+a=-6-6=-12


When I answer this question, I think that ' 1 ' is different from 1, it is not sure, but even if it is ' 1 ', there is a value difference between the character constants can be converted.

1.6 Other content?

    • The first digit in decimal cannot be 0, the first digit of octal must be 0, the first hex must have a prefix of 0x or 0X
    • Forcing type conversions
      (Type-name) expression;
      Int (3.8) gets 3
    • Bitwise operations (BITS operations)
      Symbol:&,|,^,-,<<,>>
2. This week's content, you are not what?
    • The use and calculation of the self-increment self-decrement operator is not good enough, error-prone
    • Use of character types, output input
    • Operator precedence and binding calculations are also error-prone
    • Conversion calculation between the binaries
    • Lack of understanding of some of the less commonly used expressions
3. Circular Structure Examination Summary

1. What is wrong with the question, and how to change it?

    • The use of the second inscription is not proficient in its own, in the definition and the conversion of letters is not proficient, in the exam is the use of debugging tools to understand the value of a 65 and then use the character and the value of the conversion relationship to derive the correct.
      Now know that Char ch= ' A ' should be defined, using ch=ch+1 to get the back letter
    • The fourth problem binary calculation, 0 of the number of their own beginning of the confusion, the program is not complex to write, and then their own in addition to two ways to consider its actual effective digits, and then use the total minus to obtain

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

    • Not satisfied
    • I should be more in touch with different types of questions, exercise their own thinking ability
    • When writing a program, think about it and write it down to reduce confusion.
    • Improve the ability of self-checking and try to find out the mistakes of running

3. Other summaries

    • In the code to pay attention to the space and line-wrapping problem, to format accurate
    • For whitespace problems can also be seen using dev-c++ debugging
    • Your own preview to be more thorough, the textbook must look carefully

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.