请对此进行调试并解决错误. [英] please debug this and solve the errors.. im nt able to bug them
本文介绍了请对此进行调试并解决错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include "stdafx.h"
Using namespace System;
class MatrixMultiplication
{
int[,] a;
int[,] b;
int[,] c;
public void ReadMatrix()
{
Console.WriteLine("\n Size of Matrix 1:");
Console.Write("\n Enter the number of rows in Matrix 1 :");
int m=int.Parse(Console.ReadLine());
Console.Write("\n Enter the number of columns in Matrix 1 :");
int n=int.Parse(Console.ReadLine());
a=new int[m,n];
Console.WriteLine("\n Enter the elements of Matrix 1:");
for(int i=0;i<a.GetLength(0);i++)
{
for(int j=0;j<a.GetLength(1);j++)
{
a[i,j]=int.Parse(Console.ReadLine());
}
}
Console.WriteLine("\n Size of Matrix 2 :");
Console.Write("\n Enter the number of rows in Matrix 2 :");
m=int.Parse(Console.ReadLine());
Console.Write("\n Enter the number of columns in Matrix 2 :");
n=int.Parse(Console.ReadLine());
b=new int[m,n];
Console.WriteLine("\n Enter the elements of Matrix 2:");
for(int i=0;i<b.GetLength(0);i++)
{
for(int j=0;j<b.GetLength(1);j++)
{
b[i,j]=int.Parse(Console.ReadLine());
}
}
}
public void PrintMatrix()
{
Console.WriteLine("\n Matrix 1:");
for(int i=0;i<a.GetLength(0);i++)
{
for(int j=0;j<a.GetLength(1);j++)
{
Console.Write("\t"+a[i,j]);
}
Console.WriteLine();
}
Console.WriteLine("\n Matrix 2:");
for(int i=0;i<b.GetLength(0);i++)
{
for(int j=0;j<b.GetLength(1);j++)
{
Console.Write("\t"+b[i,j]);
}
Console.WriteLine();
}
Console.WriteLine("\n Resultant Matrix after multiplying Matrix 1 & Matrix 2:");
for(int i=0;i<c.GetLength(0);i++)
{
for(int j=0;j<c.GetLength(1);j++)
{
Console.Write("\t"+c[i,j]);
}
Console.WriteLine();
}
}
public void MultiplyMatrix()
{
if(a.GetLength(1)==b.GetLength(0))
{
c=new int[a.GetLength(0),b.GetLength(1)];
for(int i=0;i<c.GetLength(0);i++)
{
for(int j=0;j<c.GetLength(1);j++)
{
c[i,j]=0;
for(int k=0;k<a.GetLength(1);k++) // OR k<b.GetLength(0)
c[i,j]=c[i,j]+a[i,k]*b[k,j];
}
}
}
else
{
Console.WriteLine("\n Number of columns in Matrix1 is not equal to Number of rows in Matrix2.");
Console.WriteLine("\n Therefore Multiplication of Matrix1 with Matrix2 is not possible");
Environment.Exit(-1);
}
}
}
class Matrix
{
public static void Main()
{
MatrixMultiplication MM=new MatrixMultiplication();
MM.ReadMatrix();
MM.MultiplyMatrix();
MM.PrintMatrix();
}
}
推荐答案
语句:
#include "stdafx.h"
不属于C#程序.
does not belong in a C# program.
如果您正确复制和粘贴代码,它将可以正常工作!
http://code.wikia.com/wiki/Matrix_multiplication [
Hi,
If you copy and paste the code properly it will work!
http://code.wikia.com/wiki/Matrix_multiplication[^]
Alan.
这篇关于请对此进行调试并解决错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文