Guest User

https://ehazi.hu/q/21407/informatika-olvassunk-be-egy-n-elem

a guest
Feb 18th, 2019
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Short
  4. {
  5.     class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             // A két egyező tömb
  10.             int [] a = { -1, 2, 4, 3, -3, 7, -4, 5 };
  11.             int [] b = { -1, 2, 4, 3, -3, 7, -4, 5 };
  12.                        
  13.             // A tomb kiíratása
  14.             foreach (var x in a) {
  15.                 Console.Write("{0,2} ",x);
  16.             }
  17.             Console.WriteLine();
  18.  
  19.             // B tömb rendezése
  20.             Array.Sort(b);
  21.  
  22.             // Megkeressük az első nem negatív számot a rendezett (B) tömbben
  23.             int k = 0;
  24.             while(b[k] < 0) {
  25.                 k++;
  26.             }
  27.  
  28.             // pozitív helyekre beillesztve a rendezett B tömb pozitív elemeit
  29.             for (int i = 0; i < a.Length; i++) {
  30.                 if (a[i] >= 0) {
  31.                     a[i] = b[k];
  32.                     k++;
  33.                 }
  34.             }
  35.  
  36.             // A tömb kiiratása (már rendezve a pozitív elemeket)
  37.             foreach (var x in a) {
  38.                 Console.Write("{0,2} ",x);
  39.             }
  40.             Console.WriteLine();
  41.  
  42.            
  43.             Console.Write("Press any key to continue . . . ");
  44.             Console.ReadKey(true);
  45.         }
  46.     }
  47. }
Add Comment
Please, Sign In to add comment