Functions and Arrays

mail@pastecode.io avatar
unknown
csharp
2 years ago
2.4 kB
2
Indexable
Never
using System;

namespace IT213M4_Hepner_C
{
    class Program
    {
        private static object stringArray;

        static void Main(string[] args)
        {
            int[] numberArray = { 56, 77, 23, 12, 88, 59, 97, 33, 38, 64 };

            //Define a string array that holds 10 strings
            String[] stringArray = new string[10];

            //Call findMax() to find the index of the largest item in the array
            int maximumIndex = findMax(numberArray.Length, numberArray);

            //Call evenOrOdd() to determine if each item in numberArray is even or odd and place 'even' or 'odd'
            //in the corresponding position in stringArray
            evenOrOdd(numberArray, stringArray, numberArray.Length);

            Console.WriteLine(" The largest value in the array is ", numberArray, maximumIndex, "located at array index" + maximumIndex);

            //Loop through the two arrays and print the integer from integer array followed by the corresponding value from the string array
            Console.WriteLine(" The numbers were: ");
            for (int i = 0; i < numberArray.Length; i++)

                Console.WriteLine(numberArray[i], " is ", stringArray[i]);

            //Keep console window open
            Console.Read();

        }

        private static int findMax(int length, int[] numberArray)
        {
            throw new NotImplementedException();
        }

        private static void evenOrOdd(int[] numberArray, string[] stringArray, int length)
        {

        //Write a function named findMax that will accept two arguments and return an integer value
        //The first parameter is an integer array. The second parameter is the size of length of the integer array        {
            int maxValue = numberArray[0];
            int maxValuePosition = 0;
            //Loop through the positions in the array, searching all items to find the largest value in the array
            for (int i = 0; i < length; i++)
            {
                //Place the appropriate value "even" or "odd" in the corresponding position of the string array
                if (numberArray[i] % 2 == 0)
                {
                    stringArray [i] = "even";
                }
                else
                {
                    stringArray [i] = "odd";
                }
            }
        }
    }
}