Problem Description
Given a string of characters, find the largest word if two or more words are the largest then display the one that occurs first in the string.
Example:
String a ={ "a", "bb", "dddd", "cccc", "ffffff", "eeeee" };
Output = ffffff;
               
Given a string of characters, find the largest word if two or more words are the largest then display the one that occurs first in the string.
Example:
String a ={ "a", "bb", "dddd", "cccc", "ffffff", "eeeee" };
Output = ffffff;
class Example
   
{
      
public static void Main()
       
{
            string[] str = new string[6] { "a", "bb", "dddd", "cccc", "ffffff", "eeeeee" };
            string temp = "";
            int a = 0;
            for (int i = 0; i < str.Length; i++)
            {
                if (a==0)
                {
                    temp = str[i];
                }
                else
                {
                    if (a < str[i].Length)
                    {
                        temp = str[i];
                    }
                }
                a = temp.Length;
            }
            Console.WriteLine(temp);
            Console.ReadLine();
       
}
    }
Output
 
 
No comments:
Post a Comment