入样例:10,3,1,5,4,8,7,2,9,11 输出样例:2,3,5,7,11 输入样例:16,12,1,6,4,8,14,18,24,21 输出样例:Not found!
时间: 2023-07-27 18:24:51 浏览: 59
【Atlas 200I DK A2 体验】部署样例 sampleYOLOV7MultiInput
代码如下:
```c
#include <stdio.h>
#include <stdbool.h>
bool is_prime(int num) {
if (num <= 1) {
return false;
}
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
void sort(int a[], int len) {
for (int i = 0; i < len - 1; i++) {
for (int j = i + 1; j < len; j++) {
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
int main() {
int a[10];
for (int i = 0; i < 10; i++) {
scanf("%d", &a[i]);
}
int primes[10];
int prime_count = 0;
for (int i = 0; i < 10; i++) {
if (is_prime(a[i])) {
primes[prime_count++] = a[i];
}
}
if (prime_count == 0) {
printf("Not found!");
return 0;
}
sort(primes, prime_count);
for (int i = 0; i < prime_count; i++) {
printf("%d", primes[i]);
if (i != prime_count - 1) {
printf(",");
}
}
return 0;
}
```
输入示例:
```
10,3,1,5,4,8,7,2,9,11
```
输出示例:
```
2,3,5,7,11
```
输入示例:
```
16,12,1,6,4,8,14,18,24,21
```
输出示例:
```
Not found!
```
阅读全文