"c language" programming habits and tricks

Source: Internet
Author: User
Tags floor function

Tips:
    • The best way to learn an algorithm is not to write a program, but to calculate hand
    • Do not figure fast-if not enough time to practice, then learn quickly, forget also fast
    • The method of manual simulation focuses on: Record the values of each variable after each statement execution
    • Black Box testing: Only the ability to solve problems and not care about what methods are used
    • Pseudo-code: in the actual application is not too rigidly tied to the format of pseudo-code, the main purpose is to describe the algorithm outline, avoid details, inspire ideas
    • Try to shorten the definition range of variables
    • Keep the program simple Keep It Easy and Stupid
1. Exact values
1 Const DoublePI = ACOs (-1.0);//accurate π values2 //Output full square number of all shapes such as AABB. Note: The range of A is 1 ~ 9, but B can be 03 //method One:4  for(intA=0; a<=9; a++) 5 { 6      for(intb=0; b<=9; b++) 7    { 8       intn = A *1100+b* One; 9       intm = Floor (sqrt (n) +0.5); Ten       if(m*m = = N) printf ("%d\n ", N);  One     }  A }  - //the floor function takes only the integer digits, and the decimal place discards - //Floor (x+0.5) in order to round up but such a small part of 0.5 will also have errors the //therefore cannot write if (sqrt (n) = = Floor (sqrt (n))) printf ("%d\n", n); -  - //Method Two: -  for(intx=1;; x + +)  + {  -     intn = x*x; +     if(N < +)Continue;  A     if(N >9999) Break;  at     inthi = n/ -;  -     intLo = n% -;  -     if(hi/Ten= = hi%Ten&& lo/Ten= = lo%Ten) printf ("%d ", N);  -}

"c language" programming habits and tricks

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.