Print Friendly and PDF
Create a function named MinMaxArray, to return the minimum and maximum values stored in an array, using reference parameters:
Create a function named MinMaxArray, to return the minimum and maximum values stored in an array, using reference parameters:

Solution:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MinMax
{
    class Program
    {
        public static void MinMaxArray(int[] number, ref int min, ref int max)
        {
            max = number[0];
            min = number[0];
            for (int i = 1; i < number.Length; i++)
            {
                if (number[i] > max)
                    max = number[i];
                if (number[i] < min)
                    min = number[i];
            }
        }
        static void Main(string[] args)
        {
            int[] data = { 3, 0, 9, 8, 4, 1 };
            int min = data[0];
            int max = data[0];
            MinMaxArray(data, ref min, ref max);
            Console.WriteLine("Minimun: {0} - Maximun: {1}",
                min, max);
            Console.ReadLine();
        }
    }
}

zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: