Answer to Question #274341 in C# for Holik

Question #274341

10. Along the main and additional diagonals of any two-dimensional square array


Create a program to find the sum of elements.

1
Expert's answer
2021-12-02T06:47:40-0500
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();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS