SoFunction
Updated on 2025-03-06

C# Method to find the maximum and minimum values ​​among n numbers

This article example describes the method of finding the maximum and minimum values ​​among n numbers in C#. Share it for your reference. The specific implementation method is as follows:

using System; 
using ; 
using ; 
using ; 
namespace ConsoleApplication2 
{ 
 class Program 
 { 
  static void Main(string[] args) 
  { 
   ("Enter ten numbers: "); 
   // int [] num = new int[10]; 
   //for (int i = 0; i < 10; i++) 
   //{ 
    string s = (); 
    // num[i] = (s); 
   // } 
    string[] num = (' ');
    //Dig out the spaces and save the numbers into the array    int[] m = new int[]; 
    for (int i = 0; i < ; i++) 
    { 
     m[i] = (num[i]); 
    } 
    ("The maximum value is: {0}",max(m,10)); 
    ("The minimum value is: {0}", min(m, 10)); 
   (); 
  } 
  static int max(int[] num, int n) 
  { 
   int a = num[0]; 
   for (int i = 0; i < n; i++) 
   { 
    if (a < num[i]) 
    { 
     a = num[i]; 
    } 
   } 
   return a; 
  } 
  static int min(int []num,int n) 
  { 
   int a = num[0]; 
   for (int i = 0; i < n; i++) 
   { 
    if (num[i] < a) 
    { 
     a = num[i]; 
    } 
   } 
   return a; 
  } 
 } 
}

I hope this article will be helpful to everyone's C# programming.