Before judging the prime numbers between 2-, we should first clearly understand the prime standard:
Prime Number: in a natural number greater than 1, apart from 1 and the integer itself, it cannot be divisible by other natural numbers.
1) Apart from 1 and itself, it cannot be divisible by other natural numbers;
2) 2 is a unique prime number that can be divisible by 2;
3) except for 2, all even numbers are numbers.
C # is implemented as follows:
// 2 is the minimum prime number Console. writeLine (2 + ""); // defines a count variable and calculates the number of prime numbers in 3-. int count = 0; // 2 is already a prime number, therefore, you only need to judge from 3 for (int I = 3; I <= 100; I ++) {// assign I to the variable xint x = I; // define an identity scalar and set the State bool flag to false; // determine whether x meets the condition for (int j = 2; j <x; j ++) {// can be divisible by 2 and any integer smaller than him. It is not a prime number if (x % j = 0) {// if it is not a prime number, flag is set to trueflag = true; // jump out of the loop and determine the next digit break;} if (flag = true) {continue;} // if the flag is false, else {// print the prime number Console. writeLine (x); count ++ ;}// count + 1 calculate all prime numbers in 2-, with a total of 25 consoles. writeLine (count + 1 );
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/192633KN-0.gif "alt =" j_0057.gif "/> for beginners, this judgment is still difficult, but with learning, you will understand what is going on.
Come on !!!
This article is from the "Lanting drunk beauty" blog and is not reposted!