![](/img/trans.png)
[英]program to find the largest and smallest among three entered numbers and also display whether the identified largest/smallest number is even or odd
[英]program to find the smallest and largest word
這是KN King書中的一個示例,該示例在一系列單詞中找到最小和最大的單詞,並以4個單詞長度停止。但是它不能正常工作。
#include <stdio.h>
#include <string.h>
#define N 20
int main(void) {
char smallest_word[N];
char largest_word[N];
char current_word[N];
printf("Enter word: ");
gets(current_word);
strcpy(smallest_word, strcpy(largest_word, current_word));
while(strlen(current_word) != 4){
printf("Enter word: ");
gets(current_word);
if(strcmp(current_word, smallest_word) < 0)
strcpy(smallest_word, current_word);
if(strcmp(current_word, largest_word) > 0)
strcpy(largest_word, current_word);
}
printf("\nSmallest word: %s\n", smallest_word);
printf("Largest word: %s\n", largest_word);
return 0;
}
假設我輸入:
cat
dog
catfish
bear
給
Output:
Smallest Word: bear
Largest Word: dog
我認為這是錯誤的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.