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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rupali ShindePosted Dec 22, 2015, 12:45 AM
Ravi PatelPosted Dec 21, 2015, 11:33 AM
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();
}
}
}