Judge the ACing of the prime number and the acing of the prime number.
1. Determine whether positive integer m is a prime number.
Int I, m; printf ("Enter a number:"); scanf ("% d", & m); for (I = 2; I <= m/2; I ++) if (m % I = 0) break; // if m can be divisible by an I, m is not a prime number, end the cycle if (I> m/2 & m! = 1) // If the loop ends normally, m cannot be divisible by any one I ("% d is a prime number! \ N ", m); else printf (" No! \ N "); return 0;
2. Use nested loops to obtain all prime numbers within 100
Int count, I, m, n; count = 0; // records the number of prime numbers, used to control the output format for (m = 2; m <= 100; m ++) {n = sqrt (m); for (I = 2; I <= n; I ++) if (m % I = 0) break; if (I> n) {// If m is a prime number printf ("% 6d", m); // output m count ++; // accumulate the number of output prime numbers if (count % 10 = 0) // if count is a multiple of 10, wrap printf ("\ n ");}} printf ("\ n"); return 0;
3. Use the function to calculate all prime numbers within 100
# Include <stdio. h> # include <math. h> int main (void) {int count, m; int prime (int m); // function declaration count = 0; // records the number of prime numbers, used to control the output format for (m = 2; m <= 100; m ++) {if (prime (m )! = 0) {// call prime (m) to determine whether m is a prime number printf ("% 6d", m); // output m count ++; // accumulate the number of output prime numbers if (count % 10 = 0) // if count is a multiple of 10, wrap printf ("\ n ");}} printf ("\ n");}/* defines the function for determining prime numbers. If m is a prime number, 1 is returned. Otherwise, 0 */int prime (int m) {int I is returned, n; if (m = 1) return 0; // 1 is not a prime number, returns 0 n = sqrt (m); for (I = 2; I <= n; I ++) {if (m % I = 0) {// return 0 if m is not a prime number; // return 0} return 1 ;}}