Life always needs an opportunity to change, in fact, rather than an opportunity, but also to give themselves a chance.
Regain the C language, I decided to give myself a chance, do not know how many years later I look at this blog when it will be how the mood, will not remember the current as a junior dog I finally want to say goodbye to nothing, no, the decadent and not know the university life, I do not want to say is for the ideal and struggle, Not just for the sake of China's rise, but for myself, that's all.
Thanks to bit, give me a chance to change.
Start from scratch and learn C language.
--------------------------------------Sensational Split Line-------------------------------------------
Find Prime Code
#include <stdio.h>//100~200 the prime number int main () {int i=0; int j=0; for (i=100;i<200;i++) {for (j=2;j<= (I/2); j + +) {if (i%j==0) break; } if (i%j!=0) printf ("is the number of primes:%d \ n", i); } return 0;}
This is the first code I wrote, after the teacher explained, found that it can actually be optimized:
#include <stdio.h>//100~200 the prime number int main () {int i=0; int j=0; for (i=101;i<200;i+=2)//minus even, reducing the number of cycles {for (j= 3;j<= (I/2); j+=2) {if (i%j==0) break; } if (i%j!=0) printf ("is the number of primes:%d \ n", i); } return 0;}
Here, there are also areas to note:
The method of seeking a prime number greater than 2 is not only N/2, but can also be n-1; or sqrt (n);
P.S: Remember to add #include<math.h> to the header file when using sqrt
This article from "10954937" blog, declined reprint!
Programming growth Diary--regain C language