How to print the array having values in the matrix form and how to print the diagonal values in that matrix?
Need the code in c-sharp...
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rupali ShindeRank #539 · 4.5K reputationPosted Dec 21, 2015, 7:45 PM EST
Ravi PatelRank #439 · 5.7K reputationPosted Dec 21, 2015, 6:33 AM EST
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
long[,] arr = new long[4, 4] { { 0, 0, 0, 0 }, { 1, 1, 1, 1 }, { 0, 0, 0, 0 }, { 1, 1, 1, 1 } };
var rowCount = arr.GetLength(0);
var colCount = arr.GetLength(1);
for (int row = 0; row < rowCount; row++)
{
for (int col = 0; col < colCount; col++)
if (row == col)
Console.Write(String.Format("{0}\t", arr[row, col]));
Console.WriteLine();
}
Console.ReadKey();
}
}
}