[英]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.