Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C# Program to Find Largest Number in an Array

This blog post shows how to write a c# program to find the largest number in an array, and find the largest two numbers in a given array.

Input | arr = { 31, -41, 26, 59, -53, 58, 97, -93, -23, 84 };
Output | First Max: 97, Second Max:84

  • Must read Introduction to C#

C# Program to Find Largest Number in an Array

// C# program to find the largest two numbers in a given array
        public static void Main()
        {
            int[] ar = { 31, -41, 26, 59, -53, 58, 97, -93, -23, 84 };
            int max1 = 0, max2 = 0;
            for (int i = 0; i  max1 && max2  max2)
                {
                    max2 = ar[i];
                }
            }
            Console.WriteLine("First Max  : {0} and Second max in array : {1} in array", max1, max2);
            Console.ReadLine();
        }

Find the 3rd largest number in an array

public static void Main()
        {
            int s = 0, l = 0, m = 0;
            int[] ar = { 12, 3, 34, 5, 3, 0, 19, 19 };
            for (int i = 0; i 

Conclusion
I hope you like the article based on C# interview questions – find the Largest Number in an array. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

The post C# Program to Find Largest Number in an Array appeared first on DotNetTec.



This post first appeared on Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps API Developer, please read the originial post: here

Share the post

C# Program to Find Largest Number in an Array

×

Subscribe to Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps Api Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×