admin管理员组文章数量:1130349
以下是一个简单的英汉翻译程序示例,使用数组来存储一些常见的单词和其对应的翻译:
c
复制
#include <stdio.h>
#include <string.h>
// 定义单词和翻译的结构体
typedef struct {
char english[50];
char chinese[50];
} WordTranslation;
int main() {
WordTranslation translations[] = {
{“apple”, “苹果”},
{“banana”, “香蕉”},
{“orange”, “橙子”},
{“dog”, “狗”},
{“cat”, “猫”}
};
int numTranslations = sizeof(translations) / sizeof(WordTranslation);
char inputWord[50];
printf("请输入要翻译的单词: ");
scanf("%s", inputWord);
int found = 0;
for (int i = 0; i < numTranslations; i++) {
if (strcmp(inputWord, translations[i].english) == 0) {
printf("%s 的翻译是: %s\n", inputWord, translations[i].chinese);
found = 1;
break;
}
}
if (!found) {
printf("未找到 %s 的翻译\n", inputWord);
}
return 0;
}
在上述代码中,您可以根据需要添加更多的单词和翻译。
以下是一个简单的英汉翻译程序示例,使用数组来存储一些常见的单词和其对应的翻译:
c
复制
#include <stdio.h>
#include <string.h>
// 定义单词和翻译的结构体
typedef struct {
char english[50];
char chinese[50];
} WordTranslation;
int main() {
WordTranslation translations[] = {
{“apple”, “苹果”},
{“banana”, “香蕉”},
{“orange”, “橙子”},
{“dog”, “狗”},
{“cat”, “猫”}
};
int numTranslations = sizeof(translations) / sizeof(WordTranslation);
char inputWord[50];
printf("请输入要翻译的单词: ");
scanf("%s", inputWord);
int found = 0;
for (int i = 0; i < numTranslations; i++) {
if (strcmp(inputWord, translations[i].english) == 0) {
printf("%s 的翻译是: %s\n", inputWord, translations[i].chinese);
found = 1;
break;
}
}
if (!found) {
printf("未找到 %s 的翻译\n", inputWord);
}
return 0;
}
在上述代码中,您可以根据需要添加更多的单词和翻译。
版权声明:本文标题:c语言编程实现英汉翻译词典代码 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754785818a2728150.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论