C#init数组 [英] C# init arrays

查看:95
本文介绍了C#init数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个可以对矩阵进行加法,乘法,减法和除法的项目。假设每个人都在一个方法中显示。我可以弄清楚加法和减法但不是乘法和除法。我还需要用户输入的帮助。用户希望在显示方法中输入值,但我在使用Console.Intt32时遇到问题。我的代码如下。

[code]

使用系统;


公共类Matrix


{


public static void Main(string [] args)


{



int [,] matrix1 = {{1,2},{3,4}};


int [,] matrix2 = {{2,3} ,{4,5}};


int [,] matrix3 = new int [2,2];


DisplayMatrix(matrix1) ;


Console.WriteLine();


DisplayMatrix(matrix2);


AddMatrix( matrix1,matrix2,matrix3);


SubtractMatrix(matrix1,matrix2,matrix3);


}


public static void DisplayMatrix(int [,] array)

{


for(int row = 0; row< array .GetLength(0); row ++)


{


for(int column = 0; column< array.GetLength(1);专栏++)


array = Convert.ToInt(Console.ReadLine());


Console.Write(" {0}" ,阿拉y [row,column]);


Console.WriteLine();


}

}


public static void AddMatrix(int [,] array1,int [,] array2,int [,] array3)


{


for(int row = 0;行< array1.GetLength(0);行++)


{


for(int column = 0; column< array1.GetLength(1); column ++)


array3 [row,column] = array1 [row,column] + array2 [row,column];


}


for(int row = 0; row< array1.GetLength(0); row ++)


{


for( int column = 0; column< array1.GetLength(1); column ++)


Console.Write(" {0}",array3 [row,column] ]);


}


Console.WriteLine();


}


public static void SubtractMatrix(int [,] array1,int [,] array2,int [,] array3)


{


for(int row = 0; row< array1.GetLength(0); row ++)


{


for(int column = 0; column< array1.GetLength(1); column ++)

array3 [row,column] = array1 [row,column] - array2 [row,专栏];


}


for(int row = 0; row< array1.GetLength (0);行++)


{


for(int column = 0; column< array1.GetLength(1); column ++)


Console.Write(" {0}",array3 [row,column]);


}


Console.WriteLine();


}



}

{/ CODE }

I''''m working on a project that will add,multipy,subtract and divide a matrix. Each one is suppose to be display in a method. I can figure out the addition and subtraction but not the multipication and divison. I also needs help with user input. The user suppose to enter the values in the Display Method, but I''m having trouble with the Console.Intt32. My code is below.
[code]
using System;

public class Matrix

{

public static void Main(string[] args)

{


int[,] matrix1 = { {1, 2 }, { 3, 4 } };

int[,] matrix2 = { { 2, 3 }, { 4, 5 } };

int[,] matrix3 = new int [2,2];

DisplayMatrix(matrix1);

Console.WriteLine();

DisplayMatrix(matrix2);

AddMatrix(matrix1, matrix2, matrix3);

SubtractMatrix(matrix1, matrix2, matrix3);

}

public static void DisplayMatrix(int[,] array)

{

for (int row=0; row < array.GetLength(0); row++)

{

for (int column = 0; column < array.GetLength(1); column++)

array=Convert.ToInt(Console.ReadLine());

Console.Write("{0}", array[ row, column]);

Console.WriteLine();


}

}

public static void AddMatrix(int[,] array1, int [,] array2, int[,] array3)

{

for(int row=0; row< array1.GetLength(0); row++)

{

for(int column=0; column <array1.GetLength( 1 ); column++)

array3[row, column] = array1 [row, column] + array2 [row, column];

}

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)


Console.Write("{0}", array3[row, column]);

}

Console.WriteLine();

}

public static void SubtractMatrix(int[,] array1, int[,] array2, int[,] array3)

{

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)

array3[row, column] = array1[row, column] - array2[row, column];

}

for (int row = 0; row < array1.GetLength(0); row++)

{

for (int column = 0; column < array1.GetLength(1); column++)

Console.Write("{0}", array3[row, column]);

}

Console.WriteLine();

}


}
{/CODE}

推荐答案

您好wkid87

请将您的代码与[code]标签放在一起以便于阅读。


我不认为Console没有Intt32方法或属性。


有一个网站,我遇到了搜索,特别是因为矩阵操作已经存在了很长时间时间
此网站提供使用的代码


欢呼
Hi wkid87
Please put your code withing [code] tags for readability.

I dont think that Console does not have a Intt32 method or property.

There is site which i came across doing a search, especially since matrix operations have been around for a very long time
This site provides the code to use

cheers



您好wkid87

请输入您的代码[代码]标签的可读性。


我这样做我认为控制台没有Intt32方法或属性。


有一个网站,我遇到了搜索,特别是因为矩阵操作已经存在很长时间了/> 此网站提供使用的代码


欢呼
Hi wkid87
Please put your code withing [code] tags for readability.

I dont think that Console does not have a Intt32 method or property.

There is site which i came across doing a search, especially since matrix operations have been around for a very long time
This site provides the code to use

cheers



感谢您的链接,但它没有任何帮助。没看到代码。


你知道如何从用户那里获取价值吗?

Thanks for the link, but it did not help any. Didn''t see the code.

Do you know how to get values from the user?



感谢您的链接,但它没有任何帮助。没看到代码。


你知道如何从用户那里获取价值吗?
Thanks for the link, but it did not help any. Didn''t see the code.

Do you know how to get values from the user?



代码将从网站上下载。

我认为它将作为一个库,其中定义了所有函数它,你需要的只是引用库并使用它中的方法。该算法应该在其中实现。


您的应用程序如何运行?

Windows应用程序,基于控制台或基于Web?


欢呼

well the code is to be donloaded from the site.
I think it will be as a library, with all the functions defined in it, all you would need is to reference the library and use the methods in it. The algorithm should be implemented within that.

How does your application run?
Windows app, Console based, or web based?

cheers


这篇关于C#init数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆