Advertisement
vovanhik_24

Task 3

Apr 8th, 2025
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Task3
  5. {
  6.     public class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] inputArray = { 1, 5, 8, 3, 10 };
  11.             int threshold = 5;
  12.  
  13.             int[] filtered = FilterGreaterThan(inputArray, threshold);
  14.  
  15.             Console.WriteLine($"Элементы больше {threshold}: {string.Join(", ", filtered)}");
  16.         }
  17.  
  18.         public static int[] FilterGreaterThan(int[] arr, int threshold)
  19.         {
  20.             List<int> result = new List<int>();
  21.  
  22.             foreach (int num in arr)
  23.             {
  24.                 if (num > threshold)
  25.                 {
  26.                     result.Add(num);
  27.                 }
  28.             }
  29.  
  30.             return result.ToArray();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement