Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
C# program to find largest number and second large number in the given numbers
7358 Views
Function 
This code find the largest number and second large number in the given five numbers.
Code
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	
	namespace ConsoleApplication1
	{
	   class Program
	   {
	       static void Main(string[] args)
	       {
	           Console.WriteLine("Enter Array Elements");
	           int SIZE = 5;
	           int[] array = new int[SIZE];
	           int l = 0, sl = 0;
	           for (int i = 0; i < SIZE; i++)
	           {
	               array[i] = Convert.ToInt32(Console.ReadLine());
	           }
	           if (array[0] < array[1])
	           {
	               l = array[1];
	               sl = array[0];
	           }
	           else
	           {
	               l = array[0];
	               sl = array[1];
	           }
	           for (int i = 2; i < SIZE; i++)
	           {
	               if (array[i] > l)
	               {
	                   sl = l;
	                   l = array[i];
	               }
	               else if (array[i] > sl)
	               {
	                   sl = array[i];
	               }
	           }
	           Console.WriteLine("Result  : \nLargest : {0} \nSecond Largest : {1}", l, sl);
	           Console.ReadLine();
	       }
	   }
	}
Output 
Previous Topics
Previous lessons of current book.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details