C程序---找最长字符串

输入5个字符串,找出其中最长的字符串

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
      int i;
      char str[80],max[80] ;
      printf("input 5 string:\n");
      scanf("%s",str);
      strcpy(max ,str);
      for(i = 1;i<5;i++)
      {
            scanf("%s",str);
            if(strcmp(max,str)<0)
                 strcpy(max ,str);
      }
      printf("max is: %s \n",max);

      return 0;

}

发布了146 篇原创文章 · 获赞 59 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/naturly/article/details/105583447