728x90
반응형
코드
using System;
using System.Collections;
namespace Matrix_Calculator {
class Matrix {
// 행과 열 변수
private int row;
private int column;
// 행렬 변수 (ArrayList 사용)
private ArrayList matrix;
// Matrix 클래스 생성자
public Matrix() {
Console.WriteLine("Matrix Creates...");
}
// Matrix 클래스 생성자 (매개 변수로 행과 열 받는 경우)
public Matrix(int _row, int _column) : this() {
this.row = _row;
this.column = _column;
}
// 행렬 입자 생성 메소드
public void inputMatrix() {
Console.WriteLine($"row : {row}, column : {column}");
matrix = new ArrayList();
// 한 행씩 입력한다.
for (int i = 0; i < row; i++) {
Console.Write("input the One Row : ");
string input = Console.ReadLine();
string[] columns = input.Split(' ');
ArrayList columns_number = new ArrayList();
for(int j = 0; j < column; j++) {
columns_number.Add(Convert.ToInt32(columns[j]));
}
matrix.Add(columns_number);
}
}
// 행과 열 입력 메소드
public void inputRowColumn() {
Console.Write("input the Row, Column (ex. 3 3) : ");
string input = Console.ReadLine();
string[] row_column = input.Split(' ');
foreach(string tmp in row_column) {
Console.WriteLine(tmp);
}
row = Convert.ToInt32(row_column[0]);
column = Convert.ToInt32(row_column[1]);
}
// 행렬 출력 메소드
public void printMatrix() {
foreach(ArrayList row in matrix) {
foreach(int column in row) {
Console.Write($"{column} ");
}
Console.Write("\n");
}
}
}
class main {
static void Main() {
Matrix m1 = new Matrix();
m1.inputRowColumn();
m1.inputMatrix();
m1.printMatrix();
}
}
}
결과 값

728x90
반응형
'제작 > 기타 프로그램' 카테고리의 다른 글
[C#] 행렬 계산기 (6) - 전체 코드 (0) | 2020.10.21 |
---|---|
[C#] 행렬 계산기 (5) - 곱셈 계산 (0) | 2020.10.21 |
[C#] 행렬 계산기 (4) - 이차원 배열로 더 간단하게 표현 (0) | 2020.10.20 |
[C#] 행렬 계산기 (3) - 대리 연산자를 활용하여 함축화 (0) | 2020.10.15 |
[C#] 행렬 계산기(2) - 더하기, 빼기 메소드 (0) | 2020.10.11 |
728x90
반응형
코드
using System;
using System.Collections;
namespace Matrix_Calculator {
class Matrix {
// 행과 열 변수
private int row;
private int column;
// 행렬 변수 (ArrayList 사용)
private ArrayList matrix;
// Matrix 클래스 생성자
public Matrix() {
Console.WriteLine("Matrix Creates...");
}
// Matrix 클래스 생성자 (매개 변수로 행과 열 받는 경우)
public Matrix(int _row, int _column) : this() {
this.row = _row;
this.column = _column;
}
// 행렬 입자 생성 메소드
public void inputMatrix() {
Console.WriteLine($"row : {row}, column : {column}");
matrix = new ArrayList();
// 한 행씩 입력한다.
for (int i = 0; i < row; i++) {
Console.Write("input the One Row : ");
string input = Console.ReadLine();
string[] columns = input.Split(' ');
ArrayList columns_number = new ArrayList();
for(int j = 0; j < column; j++) {
columns_number.Add(Convert.ToInt32(columns[j]));
}
matrix.Add(columns_number);
}
}
// 행과 열 입력 메소드
public void inputRowColumn() {
Console.Write("input the Row, Column (ex. 3 3) : ");
string input = Console.ReadLine();
string[] row_column = input.Split(' ');
foreach(string tmp in row_column) {
Console.WriteLine(tmp);
}
row = Convert.ToInt32(row_column[0]);
column = Convert.ToInt32(row_column[1]);
}
// 행렬 출력 메소드
public void printMatrix() {
foreach(ArrayList row in matrix) {
foreach(int column in row) {
Console.Write($"{column} ");
}
Console.Write("\n");
}
}
}
class main {
static void Main() {
Matrix m1 = new Matrix();
m1.inputRowColumn();
m1.inputMatrix();
m1.printMatrix();
}
}
}
결과 값

728x90
반응형
'제작 > 기타 프로그램' 카테고리의 다른 글
[C#] 행렬 계산기 (6) - 전체 코드 (0) | 2020.10.21 |
---|---|
[C#] 행렬 계산기 (5) - 곱셈 계산 (0) | 2020.10.21 |
[C#] 행렬 계산기 (4) - 이차원 배열로 더 간단하게 표현 (0) | 2020.10.20 |
[C#] 행렬 계산기 (3) - 대리 연산자를 활용하여 함축화 (0) | 2020.10.15 |
[C#] 행렬 계산기(2) - 더하기, 빼기 메소드 (0) | 2020.10.11 |