aklim007

knine

Oct 18th, 2011
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace TestConsoleApplication1
  6. {
  7.     class Program
  8.     {  
  9.         static void Main(string[] args)
  10.         {
  11.             //размерность матрицы
  12.             int mSize = 5;
  13.             Random rand = new Random();
  14.             //счётчики
  15.             int i, j;
  16.             double [,] matrix ;
  17.             matrix = new double [mSize,mSize];
  18.             for (i = 0; i < mSize; i++)
  19.                 for (j = 0; j < mSize; j++)
  20.                     matrix[i, j] = rand.Next(-10000, 10000) / 15.2486;
  21.  
  22.             printMatrix(matrix, mSize, "F5", 13);
  23.         }
  24.  
  25.         public static void printMatrix(double[,] matrix, int mSize, string format, int numberSize)
  26.         {
  27.             int i, j, k;
  28.             string space;//храним пробелы
  29.             string toStr;//число преобразованное в строку
  30.             for (i = 0; i < mSize; i++)
  31.             {
  32.                 for (j = 0; j < mSize; j++)
  33.                 {
  34.                     toStr = matrix[i,j].ToString(format);
  35.                     for (k = toStr.Length, space = ""; k < numberSize; k++) space += " ";
  36.                     Console.Write(space + toStr + " ");
  37.                 }
  38.                 Console.Write(Environment.NewLine);
  39.             }
  40.  
  41.             Console.ReadKey();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment