Advertisement
LuftAffe

17_17

Apr 11th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Lab17
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main (string[] args)
  8.         {
  9.             double[,] a = {{2, 4, -6, 7.4},{4.5, -3, 5, 0},
  10.                 {9.7, 4.2, -3.8, 2.75},{3.3, -0.6, 0, 3.5}};
  11.             double[,] b = {{-1.2, 3, 0},{2.5, 6.3, 1},{1.1, 2, 4.2}};
  12.             double[,] c = new double[5, 5];
  13.             double[,] d = new double[6, 6];
  14.             for(int i = 0; i < 5; ++i)
  15.                 for(int j = 0; j < 5; ++j)
  16.                     c[i, j] = (1 + j) * i * i + j;
  17.             for(int i = 0; i < 6; ++i)
  18.                 for(int j = 0; j < 6; ++j)
  19.                     d[i, j] = Math.Sin(j * i) + 2.2;
  20.             Console.WriteLine("Matrix A:");
  21.             output(a);
  22.             Console.WriteLine("Matrix B:");
  23.             output(b);
  24.             Console.WriteLine("Matrix C:");
  25.             output(c);
  26.             Console.WriteLine("Matrix D:");
  27.             output(d);
  28.             change(a);
  29.             change(b);
  30.             change(c);
  31.             change(d);
  32.             Console.WriteLine("Matrices after change:");
  33.             Console.WriteLine("Matrix A:");
  34.             output(a);
  35.             Console.WriteLine("Matrix B:");
  36.             output(b);
  37.             Console.WriteLine("Matrix C:");
  38.             output(c);
  39.             Console.WriteLine("Matrix D:");
  40.             output(d);
  41.         }
  42.         static double min(double a, double b){
  43.             if (a < b)
  44.                 return a;
  45.             else
  46.                 return b;
  47.         }
  48.         static void change(double[,] a){
  49.             int n = a.GetLength(0);
  50.             int m = a.GetLength(1);
  51.             double mn = a[0, 0];
  52.             for (int i = 0; i < n; ++i)
  53.                 for (int j = 0; j < m; ++j)
  54.                     mn = min (a[i, j], mn);
  55.             a [0, 0] = mn;
  56.         }
  57.         static void output(double[,] a){
  58.             int n = a.GetLength(0);
  59.             int m = a.GetLength(1);
  60.             for (int i = 0; i < n; ++i, Console.WriteLine())
  61.                 for (int j = 0; j < m; ++j)
  62.                     Console.Write ("{0,6:F} ", a[i, j]);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement