def find_four_numbers(a, x): n = len(a) for i in range(n-3): for j in range(i+1, n-2): for k in range(j+1, n-1): for l in range(k+1, n): if a[i] + a[j] + a[k] + a[l] == x: return 1 return 0换成c语言
时间: 2023-06-25 14:04:36 浏览: 81
以下是将 Python 代码转换为 C 代码的结果:
```c
#include <stdio.h>
int find_four_numbers(int a[], int n, int x) {
int i, j, k, l;
for (i = 0; i <= n - 4; i++) {
for (j = i + 1; j <= n - 3; j++) {
for (k = j + 1; k <= n - 2; k++) {
for (l = k + 1; l <= n - 1; l++) {
if (a[i] + a[j] + a[k] + a[l] == x) {
return 1;
}
}
}
}
}
return 0;
}
int main() {
int a[] = {1, 2, 3, 4, 5};
int n = sizeof(a) / sizeof(int);
int x = 10;
if (find_four_numbers(a, n, x)) {
printf("Found\n");
} else {
printf("Not found\n");
}
return 0;
}
```
注意,由于 C 语言中没有内置的列表类型,因此我们需要显式传递列表的长度作为参数。
阅读全文