# 编写程序：判断素数的个数

<p>在一个数组A中存放100个数据&#xff0c;用子函数判断该数组中哪些是素数&#xff0c;并统计该素数的个数&#xff0c;在主函数中输出该素数的个数</p>

以下程序实现了这一功能，请你填补空白处内容：

```cpp
#include <stdio.h>
#include <stdlib.h>
int isPrime(int n)
{
    int i;
    if (n < 2)
        return 0;
    _______________;
    return 1;
}
int CountPrime(int a[], int size)
{
    int i = 0, count = 0;
    for (i = 0; i < size; i++)
    {
        if (isPrime(a[i]))
        {
            printf("%d ", a[i]);
            count++;
            if (count % 10 == 0)
                printf("\n");
        }
    }
    printf("\n");
    return count;
}
int main()
{
    int a[100], i, count = 0;
    for (i = 0; i < 100; i++)
        a[i] = rand() % 1000;
    printf("素数的个数:%d\n", CountPrime(a, 100));
    return 0;
}
```

## template

```cpp
#include <stdio.h>
#include <stdlib.h>
int isPrime(int n)
{
    int i;
    if (n < 2)
        return 0;
    for (i = 2; i * i <= n; ++i)
    {
        if (n % i == 0)
            return 0;
    }
    return 1;
}
int CountPrime(int a[], int size)
{
    int i = 0, count = 0;
    for (i = 0; i < size; i++)
    {
        if (isPrime(a[i]))
        {
            printf("%d ", a[i]);
            count++;
            if (count % 10 == 0)
                printf("\n");
        }
    }
    printf("\n");
    return count;
}
int main()
{
    int a[100], i, count = 0;
    for (i = 0; i < 100; i++)
        a[i] = rand() % 1000;
    printf("素数的个数:%d\n", CountPrime(a, 100));
    return 0;
}
```

## 答案

```cpp
for (i = 2; i * i <= n; ++i)
{
	if (n % i == 0)
		return 0;
}
```

## 选项

### A

```cpp
for (i = 2; i <= n; ++i)
{
	if (n % i == 0)
		return 0;
}
```

### B

```cpp
for (i = 2; i * i <= n; ++i)
{
	if (n % i == 0)
		return 1;
}
```

### C

```cpp
for (i = 2; i * i <= n; ++i)
{
	if (n / i == 0)
		return 0;
}
```