Advertisement
abasar

Exercises 24/2/16

Feb 24th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. //#1
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10.     class Program
  11.     {
  12.         public static void PrintMatrix(int [,] a)
  13.         {
  14.             for (int i = 0; i < a.GetLength(0); i++)
  15.             {
  16.                 for (int j = 0; j < a.GetLength(1); j++)
  17.                     Console.Write("{0,-7}", a[i, j]);
  18.                 Console.WriteLine();
  19.             }
  20.         }
  21.         public static void Kelet(int[,] a)
  22.         {
  23.             for (int i = 0; i < a.GetLength(0); i++)
  24.                 for (int j = 0; j < a.GetLength(1); j++)
  25.                 {
  26.                     a[i, j] = int.Parse(Console.ReadLine());
  27.                 }
  28.         }
  29.         static void Main(string[] args)
  30.         {
  31.             int[,] a = new int[6, 7];
  32.             Kelet(a);
  33.             PrintMatrix(a);
  34.             for (int i = 0; i < a.GetLength(0); i++)
  35.             {
  36.                 for (int j = 0; j < a.GetLength(1); j++)
  37.                 {
  38.                     if (j == 0)
  39.                         a[i, j] += 1000;
  40.                     else
  41.                         a[i, j] += 100;
  42.                 }
  43.             }
  44.             PrintMatrix(a);
  45.         }
  46.     }
  47. }
  48.  
  49. //#2
  50. using System;
  51. using System.Collections.Generic;
  52. using System.Linq;
  53. using System.Text;
  54. using System.Threading.Tasks;
  55.  
  56. namespace ConsoleApplication1
  57. {
  58.     class Program
  59.     {
  60.         public static void PrintMatrix(int[,] a)
  61.         {
  62.             for (int i = 0; i < a.GetLength(0); i++)
  63.             {
  64.                 for (int j = 0; j < a.GetLength(1); j++)
  65.                     Console.Write("{0,-7}", a[i, j]);
  66.                 Console.WriteLine();
  67.             }
  68.         }
  69.         public static void Kelet(int[,] a)
  70.         {
  71.             for (int i = 0; i < a.GetLength(0); i++)
  72.                 for (int j = 0; j < a.GetLength(1); j++)
  73.                     a[i, j] = int.Parse(Console.ReadLine());
  74.         }
  75.         public static int SumMatrix(int[,] a)
  76.         {
  77.             int sum = 0;
  78.             for (int i = 0; i < a.GetLength(0); i++)
  79.                 for (int j = 0; j < a.GetLength(1); j++)
  80.                     sum += a[i, j];
  81.             return sum;
  82.         }
  83.         static void Main(string[] args)
  84.         {
  85.             int[,] a = new int[5, 5];
  86.             Kelet(a);
  87.             Console.WriteLine(SumMatrix(a));
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement