ARRAY program in C sharp | source code
namespace array_2d
{
class Program
{
static void Main(string[] args)
{
int[,] mat = new int[3, 3];
int i, j,sum=0;
Console.WriteLine("Enter 9 elements:");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
Console.WriteLine("Enter element:");
mat[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
Console.WriteLine("\nThe array entered is:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
Console.Write(mat[i, j]+"\t");
Console.WriteLine("\n");
}
Console.WriteLine("The sum of array elments is:");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
sum=sum + mat[i, j];
}
Console.WriteLine(sum);
Console.ReadLine();
}
}
}
namespace array_2d
{
class Program
{
static void Main(string[] args)
{
int[,] mat = new int[3, 3];
int i, j,sum=0;
Console.WriteLine("Enter 9 elements:");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
Console.WriteLine("Enter element:");
mat[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
Console.WriteLine("\nThe array entered is:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
Console.Write(mat[i, j]+"\t");
Console.WriteLine("\n");
}
Console.WriteLine("The sum of array elments is:");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
sum=sum + mat[i, j];
}
Console.WriteLine(sum);
Console.ReadLine();
}
}
}
0 comments: