[ThinkingInC ++] 20. Exercises about C (2)
/*** Function: compile a program to use the two-for Loop and modulo operator (%) to find and output the prime number (only integers divisible by 1 and itself ). * Time: August 15, 2014 08:19:48 * Author: cutter_point */# include
# Include
Using namespace std; // write a function output prime number (only integers divisible by 1 and itself *) void printZhiShu (int n) // returns the prime number between 0 and number {cout <1 <"\ t is the prime number \ n"; // uses a two-fold for loop, modulo operator (%), 1 does not need to think // a layer of loop is weighted 2 to n. These numbers are searched for one by one (int I = 2; I <= n; ++ I) {// when the value is 2, only the modulo itself can be modulo 0 for (int j = 2; j <= I; ++ j) {int m = I % j; // modulo j if (j! = I & m = 0) {break; // if it is not a prime number, immediately exclude} cout <
> I; if (I <0) {cout <"Please do not enter a negative number !! "<