请用C语言写下面题目: 给定元素序列a,b,c,d,e,f,g,h,i,j对应的权重集合{1,4,24,5,6,10,8,31,22,11},
时间: 2023-10-08 09:13:14 浏览: 27
以下是使用C语言实现给定元素序列a,b,c,d,e,f,g,h,i,j对应的权重集合{1,4,24,5,6,10,8,31,22,11}的代码:
```c
#include <stdio.h>
int main() {
char elements[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
int weights[] = {1, 4, 24, 5, 6, 10, 8, 31, 22, 11};
int len = sizeof(elements) / sizeof(elements[0]); // 获取元素序列的长度
// 输出元素和对应权重
for (int i = 0; i < len; i++) {
printf("%c: %d\n", elements[i], weights[i]);
}
return 0;
}
```
输出结果为:
```
a: 1
b: 4
c: 24
d: 5
e: 6
f: 10
g: 8
h: 31
i: 22
j: 11
```