Guest User

Untitled

a guest
May 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 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 csere(int[,] tabla, int elso, int masodik)
  38.         {
  39.             int temp;
  40.            
  41.             for(int i = 0; i < 10; i++)
  42.             {
  43.                 temp = tabla[elso,i];
  44.                 tabla[elso,i] = tabla[masodik,i];
  45.                 tabla[masodik, i] = temp;
  46.             }
  47.            
  48.         }
  49.        
  50.         public static void csere(int[,] tabla)
  51.         {
  52.             for(int i = 0; i < 9; i+=2)
  53.             {
  54.                 csere (tabla,i,i+1);
  55.             }
  56.         }
  57.        
  58.         public static int[] atlo(int[,] tabla)
  59.         {
  60.             int[] temp = new int[10];
  61.            
  62.             for(int i = 0; i < 10; i++)
  63.             {
  64.                 temp[i] = tabla[i,i];
  65.             }
  66.            
  67.             return temp;
  68.         }
  69.        
  70.         public static int osszegez(int[] tomb)
  71.         {
  72.             int sum = 0;
  73.            
  74.             foreach(int elem in tomb)
  75.                 sum += elem;
  76.            
  77.             return sum;
  78.         }
  79.        
  80.         public static void Main (string[] args)
  81.         {
  82.            
  83.             int[,] tabla = new int[10,10];
  84.            
  85.             feltolt (tabla);
  86.             kiir(tabla);
  87.             Console.WriteLine ();
  88.             csere (tabla);
  89.             kiir (tabla);          
  90.             Console.WriteLine ();
  91.             Console.WriteLine ("Átló összege: "+osszegez (atlo(tabla)));
  92.            
  93.             Console.ReadKey ();
  94.            
  95.            
  96.         }
  97.     }
  98. }
Add Comment
Please, Sign In to add comment