Program to search for string having maximum characters


C File =>


/* Write a program to accept names of ‘n’ cities. Find the name of the city having maximum characters.*/


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


int main()
{
       int n,flag=0,i,max=0;
       char str[50][50],s[50];
       printf("\n Enter how many strings? ");
       scanf("%d",&n);
      for(i=0;i<n;i++)
     {
        printf("\n Enter String%d : ",i+1);
        scanf("%s",str[i]);
      }
     for(i=0;i<n;i++)
    {
         if(max<strlen(str[i]))
        {
           max=strlen(str[i]);
           strcpy(s,str[i]);
         }
     }
     printf("\n String with maximum length : %s",s);
  return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.