Practice Exercises C# Sharp - Learn to program with performing exercises C# Sharp

Practice Exercises C# Sharp

Learn to program with performing exercises C# Sharp

MinMaxArray - Practice Exercises C# Sharp
Practice Exercises C# Sharp4,85320940

MinMaxArray - Practice Exercises C# Sharp


Lesson 5:

Functions


Exercise 5.33:

MinMaxArray


Objetive:

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

float[] data={1.5f, 0.7f, 8.0f}
MinMaxArray(data, ref minimum, ref maximum);
(after that call, minimum would contain 0.7, and maximum would contain 8.0)


Source Code:


using System;
public class F_MinMax
{
    public static void MinMaxArray(float[] number, ref float min, ref float 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];
        }

    }

    public static void Main(string[] args)
    {
        float[] data = { 3.5f, 0.5f, 9, 0f };
        float min = 0.0f;
        float max = 0.0f;

        MinMaxArray(data, ref min, ref max);

        Console.WriteLine("Minimun: {0} - Maximun: {1}", min, max);
    }
}
Exercisey 5.33

Share Now:







Privacy Policy:



Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.

Cookies

This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.