Posts

Showing posts from September, 2023

C#

  C# 2nd highest number print from array static void Main () { // Create an array of integers int [] numbers = { 10 , 5 , 17 , 8 , 25 , 3 , 12 };           // Find the maximum number using LINQ's Max method int maxNumber = numbers.Max(); // Sort the array in descending order Array.Sort(numbers, (a, b) => b.CompareTo(a)); // Check if there are at least two elements in the array if (numbers.Length >= 2 ) { // Print the second highest number Console.WriteLine( "The second highest number is: " + numbers[ 1 ]); } else { Console.WriteLine( "The array does not have a second highest number." ); } } ------------------ using System; using System.Threading; using System.Threading.Tasks; class Program { static void Main () { // Create an array of integers int [] numbers = { 1 , 2