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;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章