A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C# Sharp for subtraction of two Matrices ?
Q:

Write a program in C# Sharp for subtraction of two Matrices ?

0

 Write a program in C# Sharp for subtraction of two Matrices ?
Test Data :
Input the size of the square matrix (less than 5): 2
Input elements in the first matrix :
element - [0],[0] : 5
element - [0],[1] : 6
element - [1],[0] : 7
element - [1],[1] : 8
Input elements in the second matrix :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
The First matrix is :

5 6
7 8
The Second matrix is :

1 2
3 4
The Subtraction of two matrix is :

4 4
4 4

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;  
public class Exercise20  
{  
    public static void Main() 
    {
        int i,j,n;
    	int[,] arr1 = new int[50,50];
		int[,] brr1 = new int[50,50];
		int[,] crr1 = new int[50,50];  
       Console.Write("\n\nSubtraction of two Matrices :\n");
       Console.Write("------------------------------\n");  
        Console.Write("Input the size of the square matrix (less than 5): ");
	   n = Convert.ToInt32(Console.ReadLine());  
    /* Stored values into the array*/
       Console.Write("Input elements in the first matrix :\n");
       for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
	           Console.Write("element - [{0},{1}] : ",i,j);
		       arr1[i,j] = Convert.ToInt32(Console.ReadLine());			   
            }
        }     
       Console.Write("Input elements in the second matrix :\n");
       for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
	           Console.Write("element - [{0},{1}] : ",i,j);
		       brr1[i,j] = Convert.ToInt32(Console.ReadLine());			   
            }
        }    
   Console.Write("\nThe First matrix is :\n");
  for(i=0;i<n;i++)
    {
      Console.Write("\n");
      for(j=0;j<n;j++)
           Console.Write("{0}\t",arr1[i,j]);
    }  
  Console.Write("\nThe Second matrix is :\n");
  for(i=0;i<n;i++)
    {
      Console.Write("\n");
      for(j=0;j<n;j++)
      Console.Write("{0}\t",brr1[i,j]);
    }
/* calculate the subtraction of the matrix */   
   for(i=0;i<n;i++)
       for(j=0;j<n;j++)
            crr1[i,j]=arr1[i,j]-brr1[i,j];
   Console.Write("\nThe Subtraction of two matrix is : \n");
   for(i=0;i<n;i++){
       Console.Write("\n");
       for(j=0;j<n;j++)
            Console.Write("{0}\t",crr1[i,j]);
   }
   Console.Write("\n\n");
  }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now