C语言单词默写代码
时间: 2023-07-09 10:20:44 浏览: 61
很好,让我来为您编写一个C语言单词默写的代码:
```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char words[10][10] = {"apple", "banana", "orange", "grape", "cherry", "peach", "lemon", "watermelon", "strawberry", "pineapple"};
int i, j, n, score = 0;
char guess[10];
srand(time(NULL));
for (i = 0; i < 5; i++) {
n = rand() % 10;
printf("Please guess the %dth word: ", i+1);
scanf("%s", guess);
if (strcmp(guess, words[n]) == 0) {
printf("Correct!\n");
score++;
}
else
printf("Wrong!\n");
}
printf("Your final score is %d.\n", score);
return 0;
}
```
这个程序会随机选择10个单词中的5个,然后要求用户猜测每个单词是什么。用户猜对一个单词,得一分,猜错不得分。最后程序会输出用户的总得分。