Q:

Write a C# Sharp program to get only the odd values from a given array of integers

0

Write a C# Sharp program to get only the odd values from a given array of integers. 
Test Data :
Only the odd values of the said array:
1
3
5
3
Only the odd values of the said array:

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums = { 1, 2, 3, 5, 4, 2, 3, 4 };
            int[] result = test(nums);
            Console.WriteLine("Only the odd values of the said array:");
            Array.ForEach(result, Console.WriteLine);
            int[] nums1 = { 2, 4, 2, 6, 4, 8 };
            result = test(nums1);
            Console.WriteLine("Only the odd values of the said array:");
            Array.ForEach(result, Console.WriteLine);
        }
        public static int[] test(int[] arr)
        {
            return arr.Where(n => n % 2 != 0).ToArray();
        }
     }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now