Advertisement
touhid_xml

Find Second Big Number

Dec 3rd, 2016
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Find_Second_Big_Number
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] myArray = new int[] { 0, 1, 2, 3, 13, 8, 5 };
  13.             int largest = int.MinValue;
  14.             int second = int.MinValue;
  15.             foreach (int i in myArray)
  16.             {
  17.                 if (i > largest)
  18.                 {
  19.                     second = largest;
  20.                     largest = i;
  21.                 }
  22.                 else if (i > second)
  23.                     second = i;
  24.             }
  25.  
  26.             Console.WriteLine(second.ToString());
  27.             Console.ReadKey();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement