Advertisement
nevenailievaa

2201682020-Domashno3

Oct 9th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. namespace Task_3
  2. {
  3.     using System;
  4.  
  5.     class Task_3
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] arr = { 1, 2, 25, -3, 75, 4, 5, 6, 10, -9, 5, 0, 15, 25, -50, -99, 0, -1025, 54, -6, -458, 56, -3, 6 };
  10.  
  11.             int[] result = SortArrayOfDescendingOrder(arr);
  12.  
  13.             PrintArray(result);
  14.         }
  15.         static int[] SortArrayOfDescendingOrder(int[] arr)
  16.         {
  17.             int[] result = new int[arr.Length];
  18.  
  19.             for (int i = 0; i < arr.Length; i++)
  20.             {
  21.                 result[i] = arr[i];
  22.             }
  23.  
  24.             for (int i = 0; i < result.Length; i++)
  25.             {
  26.                 for (int j = 1; j < result.Length - i; j++)
  27.                 {
  28.                     if (result[j - 1] < result[j])
  29.                     {
  30.                         int swap = result[j - 1];
  31.                         result[j - 1] = result[j];
  32.                         result[j] = swap;
  33.                     }
  34.                 }
  35.             }
  36.  
  37.             return result;
  38.         }
  39.         static void PrintArray(int[] arr)
  40.         {
  41.             string s = "";
  42.  
  43.             for (int i = 0; i < arr.Length; i++)
  44.             {
  45.                 s += $"{arr[i]} ";
  46.             }
  47.  
  48.             Console.WriteLine(s);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement