10. Along the main and additional diagonals of any two-dimensional square array
Create a program to find the sum of elements.
using System;
using System.Collections.Generic;
namespace App
{
class Program
{
public static void Main()
{
Console.Write("Enter size of the square array: ");
int size = int.Parse(Console.ReadLine());
int[,] squareArray = new int[size, size];
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
Console.Write("Enter element[{0}][{1}]: ", i, j);
squareArray[i, j] = int.Parse(Console.ReadLine());
}
}
int sum = 0;
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
sum += squareArray[i, j];
}
}
Console.WriteLine("The sum of elements: {0}", sum);
Console.ReadLine();
}
}
}
Comments
Leave a comment