Advertisement
nevenailievaa

2201682020-Domashno3

Oct 8th, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. namespace Homework3
  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.  
  16.         static int[] SortArrayOfDescendingOrder(int[] arr)
  17.         {          
  18.             int[] result = new int[arr.Length];
  19.  
  20.             for (int i = 0; i < arr.Length; i++)
  21.             {
  22.                 result[i] = arr[i];
  23.             }
  24.  
  25.             for (int i = 0; i < result.Length; i++)
  26.             {
  27.                 for (int j = 1; j < result.Length - i; j++)
  28.                 {
  29.                     if (result[j - 1] < result[j])
  30.                     {
  31.                         int swap = result[j - 1];
  32.                         result[j - 1] = result[j];
  33.                         result[j] = swap;
  34.                     }
  35.                 }
  36.             }
  37.  
  38.             return result;
  39.         }
  40.  
  41.         {
  42.             string s = "";
  43.  
  44.             for (int i = 0; i < arr.Length; i++)
  45.             {
  46.                 s += $"{arr[i]} ";
  47.             }
  48.  
  49.             Console.WriteLine(s);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement