Заменить нулевые значения матрицы на 200 - C#
Формулировка задачи:
ДОбрый день, помогите пожалуйста, дана матрица, надо нулевые значения сменить на 200, я как бы пытался сделать это, но у меня диагональные меняет, а нужно только нулевые) Спасибо заранее
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lab17
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Передача двовимірних масивів у якості параметрів методів";
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Clear();
double[,] a = {{ 2, 4, -6, 7.4 }, {4.5, -3, 5, 0 },
{9.7, 4.2, -3.8, 2.75 }, { 3.3, -0.6, 0, 3.5 } };
double[,] b = { { -1 - 2, 3, 0 }, { 2.5, 6.3, 1 }, { 1.1, 2, 4.2 } };
double[,] c = new double[5, 5];
for (int i = 1; i <= c.GetLength(0); i++)
for (int j = 1; j <= c.GetLength(1); j++)
c[i - 1, j - 1] = (1 + j) * i * i + j;
double[,] d = new double[6, 6];
for (int i = 1; i <= d.GetLength(0); i++)
for (int j = 1; j <= d.GetLength(1); j++)
d[i - 1, j - 1] = Math.Sin(i * j) + 2.2;
Console.WriteLine("Матриці до виконання заміни:");
Console.WriteLine("Матриця А:");
Vyvid(a);
Console.WriteLine("Матриця B:");
Vyvid(b);
Console.WriteLine("Матриця C:");
Vyvid(c);
Console.WriteLine("Матриця D:");
Vyvid(d);
Zamina(a);
Zamina(b);
Zamina(c);
Zamina(d);
Console.WriteLine("Матриці після виконання заміни:");
Console.WriteLine("Матриця А:");
Vyvid(a);
Console.WriteLine("Матриця B:");
Vyvid(b);
Console.WriteLine("Матриця C:");
Vyvid(c);
Console.WriteLine("Матриця D:");
Vyvid(d);
Console.ReadKey();
}
static void Vyvid(double[,] w)
{
for (int i = 0; i < w.GetLength(0); i++)
{
for (int j = 0; j < w.GetLength(1); j++)
Console.Write("{0,6:F} ", w[i, j]);
Console.WriteLine();
}
}
static void Zamina(double[,] w)
{
double min = w[0, 0];
for (int i = 0; i < w.GetLength(0); i++)
for (int j = 0; j < w.GetLength(0); j++)
if (w[i, j] < min) min = w[i, j];
for (int i = 0; i < w.GetLength(0); i++)
w[i, i] = 200;
}
}
}Решение задачи: «Заменить нулевые значения матрицы на 200»
textual
Листинг программы
static void Main(string[] args)
{
var arr = new[,]
{
{1, 2, 0},
{5, 0, 4},
{55, 8, 0}
};
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
if (arr[i, j] == 0)
arr[i, j] = 200;
}
}
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
Console.Write(arr[i, j] + " ");
}
Console.WriteLine();
}
}