Aim:
To find the second largest number using c sharp.net application.Algorithms:
Step1: Start the program.Step2: Open the new text document and type the program in the text document.
Step3: Create the class named as a program name.
Step4: Initialize the variable a, i, high, sechigh, temp in the main function
Step5: Using the int parse keyword use can get the integer.
Step6: Using the for loop condition to determine the length of the array.
Step7: Using the if-else statement to pick the second highest number in the given array.
Step8: Save the program with the extension of “.cs”
Step9: Compile and run the program.
Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication_seclar
{
class Program
{
static void Main(string[] args)
{
int a, i, high, sechigh, temp;
Console.WriteLine("enter array length:");
a = int.Parse(Console.ReadLine());
int[] arr = new int[a];
Console.WriteLine("enter array element one by one");
for (i = 0; i < a; i++)
arr[i] = int.Parse(Console.ReadLine());
Console.WriteLine("array element are");
for (i = 0; i <arr.Length; i++)
Console.Write(arr[i] + "");
Console.WriteLine();
Console.WriteLine();
high = sechigh =arr[0];
for (i = 0; i <arr.Length; i++)
{
temp = arr[i];
if (temp > high)
{
sechigh = high;
high = temp;
}
else if (temp >sechigh&& temp != high)
sechigh = temp;
}
Console.WriteLine("the second largest num is" + sechigh);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication_seclar
{
class Program
{
static void Main(string[] args)
{
int a, i, high, sechigh, temp;
Console.WriteLine("enter array length:");
a = int.Parse(Console.ReadLine());
int[] arr = new int[a];
Console.WriteLine("enter array element one by one");
for (i = 0; i < a; i++)
arr[i] = int.Parse(Console.ReadLine());
Console.WriteLine("array element are");
for (i = 0; i <arr.Length; i++)
Console.Write(arr[i] + "");
Console.WriteLine();
Console.WriteLine();
high = sechigh =arr[0];
for (i = 0; i <arr.Length; i++)
{
temp = arr[i];
if (temp > high)
{
sechigh = high;
high = temp;
}
else if (temp >sechigh&& temp != high)
sechigh = temp;
}
Console.WriteLine("the second largest num is" + sechigh);
Console.ReadLine();
}
}
}
OUTPUT:
BY
REGU RAM SV.
regu suprb da,it is very useful to us and programers and coders and day to day computer informations
ReplyDeletePost a Comment