Answer to Question #175828 in C# for Patrick Ian Kyle Mabunay

Question #175828

Write a program using two-dimensional arrays that computes the sum of data in rows and sum of data in columns of the 3x3 (three by three) array variable n[3[3].


Sample input/output dialogue:

5 9 8 = 22

3 8 2 = 13

4 3 9 = 16

---------------

12 20 19


1
Expert's answer
2021-03-26T16:21:00-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Q175828
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] values = new int[3, 3];
            int[,] sums = new int[3, 2];


            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Console.Write("Enter value [{0},{1}]: ", i, j);
                    values[i, j] = int.Parse(Console.ReadLine());
                    sums[i, 0] = 0;
                    sums[i, 1] = 0;
                }
            }
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    sums[i,0] += values[i,j];
                    sums[i,1] += values[j,i];
                }
            }
            Console.WriteLine();
            for (int i = 0; i < 3; i++){
                for (int j = 0; j < 3; j++)
                {
                    Console.Write("{0}  ", values[i, j]);
                }
                Console.WriteLine(" =  {0}", sums[i,0]);
            }
            Console.WriteLine("---------------");
            for (int i = 0; i < 3; i++)
            {
                Console.Write("{0} ",sums[i, 1]);
            }
            Console.WriteLine();
            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
New on Blog
APPROVED BY CLIENTS