Advertisement
mmayoub

sham, subMatrix

Oct 26th, 2021
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class submatrix
  9.     {
  10.         private int row;
  11.         private int col;
  12.         private int[,] mat;//= new int[ row, col];
  13.         public submatrix(int row, int col)
  14.         {
  15.             this.row = row;
  16.             this.col = col;
  17.             this.mat = new int[row, col];
  18.         }
  19.  
  20.         public void Build(int a)
  21.         {
  22.  
  23.             Random rnd = new Random();
  24.             for (int c = 0; c < col; c++)
  25.                 for (int r = 0; r < row; r++)
  26.                     mat[r, c] = rnd.Next(-a, a + 1);
  27.  
  28.         }
  29.  
  30.         public bool issubmatrix()
  31.         {
  32.             int k = 0;
  33.             for (int r = 0; r < row; r++)
  34.                 for (int c = 0; c < col; c++)
  35.                     if (mat[r, c] != 0)
  36.                         k++;
  37.  
  38.  
  39.  
  40.  
  41.             if (k < (row * col) / 2)
  42.                 return true;
  43.             else
  44.                 return false;
  45.  
  46.         }
  47.  
  48.         public void print()
  49.         {
  50.             for (int r = 0; r < row; r++)
  51.             {
  52.                 for (int c = 0; c < col; c++)
  53.                 {
  54.  
  55.                     Console.Write("{0,5}", mat[r, c]);
  56.  
  57.                 }
  58.  
  59.                 Console.WriteLine();
  60.             }
  61.         }
  62.     }
  63. }
  64.  
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement