[C] language input a positive integer, determine whether it is a prime number

素数的定义:
素数(prime number)又称质数,有无限个。
素数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数,这样的数称为素数。

代码1:
#include <stdio.h>
 int main () 
{ 
    int m, n-; 
    the printf ( " Enter a positive integer: \ n- " ); 
    scanf_s ( " % D " , & m); 
    
    for (= n- 2 ; n-< m - . 1 ; n-= n-+ . 1 )
     IF (m% n-== 0 )
         BREAK ;
     IF (n-< m) 
        the printf ( " % D than the number \ n prime " , m);
     the else 
        the printf ( " % D is a prime number \ n- " , m); 
}

 Code 2:

#include <stdio.h>
 int main () 
{ 
    int m, n-; 
    n- = 2 ; 
    the printf ( " Enter a positive integer: \ n- " ); 
    scanf_s ( " % D " , & m);
     the while (n-< m - . 1 ) 
    
    IF (% n-m == 0 )
         BREAK ;
     the else 
    n- = n-+ . 1 ;
     IF (n-< m) 
        
    the printf ( " % D is not prime \ n- " , m);
     the else 
        the printf ( "is a prime number% d \ n- " , m); 
}

 

Guess you like

Origin www.cnblogs.com/HGNET/p/11853895.html