Advertisement
nahidjamalli

Lesson #8

Mar 26th, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MyNamespace
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int[] list = { 2, 3, 6, 1, 0, 9, 11 };
  10.             int eded = 7;
  11.             int[] yeniList = yeniEdedler(list, eded);
  12.  
  13.             for (int i = 0; i < yeniList.Length; i++)
  14.                 Console.Write(yeniList[i] + ", ");
  15.  
  16.             Console.WriteLine();
  17.         }
  18.  
  19.         static int[] yeniEdedler(int[] list, int eded)
  20.         {
  21.             int length = 0;
  22.             for (int i = 0; i < list.Length; i++)
  23.                 if (list[i] > eded) length++;
  24.  
  25.             int[] arr = new int[length];
  26.             int j = 0;
  27.  
  28.             for (int i = 0; i < list.Length; i++)
  29.                 if (list[i] > eded)
  30.                 {
  31.                     arr[j++] = list[i];
  32.                 }
  33.  
  34.             return arr;
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement