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