帮我写‘c语言程序输入一组英文单词,按字典顺序排序后输出
时间: 2023-03-28 12:00:30 浏览: 96
好的,以下是程序:
```c
#include <stdio.h>
#include <string.h>
#define MAX_WORDS 100
#define MAX_WORD_LEN 50
int main() {
char words[MAX_WORDS][MAX_WORD_LEN];
int n;
printf("请输入单词个数:");
scanf("%d", &n);
printf("请输入单词:\n");
for (int i = ; i < n; i++) {
scanf("%s", words[i]);
}
// 冒泡排序
for (int i = ; i < n - 1; i++) {
for (int j = ; j < n - i - 1; j++) {
if (strcmp(words[j], words[j + 1]) > ) {
char temp[MAX_WORD_LEN];
strcpy(temp, words[j]);
strcpy(words[j], words[j + 1]);
strcpy(words[j + 1], temp);
}
}
}
printf("按字典顺序排序后的单词为:\n");
for (int i = ; i < n; i++) {
printf("%s\n", words[i]);
}
return ;
}
```
希望对您有帮助!