题解 | #牛牛的素数判断#
牛牛的素数判断
https://www.nowcoder.com/practice/81c8387f72824cceb5c955e3dbfd2882
#include <stdio.h> #define N 20 int is_prime(int n); int main(void) { int n = 0; int num[N] = {0}; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", num + i); } for (int i = 0; i < n; i++) { if (is_prime(*(num + i))) { printf("true\n"); } else { printf("false\n"); } } return 0; } int is_prime(int n) { int flag = 1; for (int i = 2; i < n; i++) { if (n % i == 0) { flag = 0; break; } } return flag; }