C/C++素数判断
改进代码,判断方式很巧妙。 # include <stdio.h> # include <stdlib.h> # include <math.h> int main ( ) { int number , limit , i ; printf ( "Input a number:" ) ; scanf_s ( "%d" , & number ) ; limit = sqrt ( number ) ; if ( number == 0 ) { printf ( "False" ) ; } else { for ( i = 2 ; i <= limit ; i ++ ) { if ( number % i == 0 ) break ; } if ( i > limit ) { printf ( "True" ) ; } else { printf ( "False" ) ; } } } 来源: CSDN 作者: 源心锁 链接: https://blog.csdn.net/qq_38331169/article/details/103986934