C prime

#include <stdio.h> int main () {
     // determines a positive integer greater than or equal to 3, is prime?
     // prime number is defined as: 1 and itself only two factors of a natural number
     // [prime]: 1 except that and itself, any other integer number can not be divisible.
     @ 0 ~ 100 primes:
     // 2,3,5,7,11,13,17,19,23,29,
     // 31,37,41,43 , 47,53,59,61,67,
     // 71,73,79,83,89,97 int A;
     int I; 
    Scanf ( " % D " , & A );
     IF ( . 3 == A) { 
        the printf ( " % D is a prime number " , A); 
    } the else {
        


    for (i = 3; i < a; ++i) {
            if (a % i == 0) {
                printf("%d不是素数", a);
                break;
            }
            if (i == a-1) {
                printf("%d是素数", a);
            }
        }
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/m-yb/p/11440665.html