Advertisement
netpeti98HU

rendezes2

Jan 10th, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.  
  8.         int[] tomb = new int[10]; Random r = new Random();
  9.         tomb[0] = 2; tomb[1] = 1; tomb[2] = 3; tomb[3] = 4; tomb[4] = 5; tomb[5] = 6; tomb[6] = 7; tomb[7] = 8;  tomb[8] = 9; tomb[9] = 10;
  10.  
  11.        
  12.  
  13.         //Rendezes
  14.         int szamlalo = 0;
  15.         for (int a = 0; a < tomb.Length; ++a)
  16.         {
  17.  
  18.             for (int b = 0; b < tomb.Length; ++b)
  19.             {
  20.  
  21.                
  22.                 if (tomb[b] > tomb[a])
  23.                 {
  24.                    
  25.                    szamlalo++;
  26.                    
  27.                    
  28.                     int c = tomb[a];
  29.                     tomb[a] = tomb[b];
  30.                     tomb[b] = c;
  31.                 }
  32.  
  33.             }
  34.  
  35.         }
  36.  
  37.         for (int i = 0; i < tomb.Length; ++i)
  38.         {
  39.             Console.Write(tomb[i] + " ");
  40.         }
  41.  
  42.         Console.WriteLine("\n" + szamlalo);
  43.        
  44.         Console.ReadLine();
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement