Guest User

Untitled

a guest
May 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2.  
  3. namespace atlo
  4. {
  5.     class MainClass
  6.     {
  7.        
  8.         public static void feltolt(int[,] tabla)
  9.         {
  10.             for(int i = 0; i < 10; i++)
  11.             {
  12.                 for(int j = 0; j < 10; j++)
  13.                 {
  14.                     int szorzat = (i+1)*(j+1);
  15.                    
  16.                     if(szorzat % 2 == 1)
  17.                         szorzat++;
  18.                    
  19.                     tabla[j,i] = szorzat;
  20.                 }
  21.             }
  22.                
  23.         }
  24.        
  25.         public static void kiir(int[,] tabla)
  26.         {
  27.             for(int i = 0; i < 10; i++)
  28.             {
  29.                 for(int j = 0; j < 10; j++)
  30.                 {
  31.                     Console.Write ("{0,3} ",tabla[i,j]);
  32.                 }
  33.                 Console.WriteLine();
  34.             }
  35.         }
  36.        
  37.         public static void elemcsere(int[,] tabla, int x1, int y1, int x2, int y2)
  38.         {
  39.             int temp;
  40.            
  41.             temp = tabla[x1,y1];
  42.             tabla[x1,y1] = tabla[x2,y2];
  43.             tabla[x2, y2] = temp;
  44.         }
  45.        
  46.         public static void sorcsere(int[,] tabla, int elso, int masodik)
  47.         {          
  48.             for(int i = 0; i < 10; i++)
  49.             {
  50.                 elemcsere (tabla,elso,i,masodik,i);
  51.             }
  52.            
  53.         }
  54.        
  55.         public static void sorcsere(int[,] tabla)
  56.         {
  57.             for(int i = 0; i < 9; i+=2)
  58.             {
  59.                 sorcsere (tabla,i,i+1);
  60.             }
  61.         }
  62.        
  63.         public static int[] atlo(int[,] tabla)
  64.         {
  65.             int[] temp = new int[10];
  66.            
  67.             for(int i = 0; i < 10; i++)
  68.             {
  69.                 temp[i] = tabla[i,i];
  70.             }
  71.            
  72.             return temp;
  73.         }
  74.        
  75.         public static int osszegez(int[] tomb)
  76.         {
  77.             int sum = 0;
  78.            
  79.             foreach(int elem in tomb)
  80.                 sum += elem;
  81.            
  82.             return sum;
  83.         }
  84.        
  85.         public static void tukroz(int[,] tabla)
  86.         {
  87.             for(int i = 0; i < 10; i++)
  88.             {
  89.                 for(int s = 1; s <= i; s++)
  90.                 {
  91.                     int x1 = i-s;
  92.                     int y1 = i;
  93.                     int x2 = i;
  94.                     int y2 = i-s;
  95.                    
  96.                     elemcsere (tabla,x1,y1,x2,y2);
  97.                 }
  98.             }
  99.         }
  100.        
  101.         public static void Main (string[] args)
  102.         {
  103.            
  104.             int[,] tabla = new int[10,10];
  105.            
  106.             feltolt (tabla);
  107.             kiir(tabla);
  108.             Console.WriteLine ();
  109.             sorcsere (tabla);
  110.             kiir (tabla);          
  111.             Console.WriteLine ();
  112.             Console.WriteLine ("Átló összege: "+osszegez (atlo(tabla)));
  113.             Console.WriteLine();
  114.             tukroz (tabla);
  115.             kiir (tabla);
  116.             Console.ReadKey ();
  117.            
  118.            
  119.         }
  120.     }
  121. }
Add Comment
Please, Sign In to add comment