Hello I need help with this problem Im using Visual Studio 2

Hello, I need help with this problem. I\'m using Visual Studio 2015 C# Web Form.....

Write a syntactically correct C# method definition called SumRow. The method should take a rectangular array of integers and a row number as it\'s parameters and should return the sum of the values in that row of the array as a result. For example, calling the function with the following array and a row of 0 would return 82+55+78 or 215.

82 55 78
91 86 73
77 81 92

Solution

Here is the solution

using System;
using System.Collections.Generic;
using System.Text;
namespace matrix_row_sum
{
    class mat
    {
        int i, j, m, n;
        int[,] a = new int[20, 20];
      
        public void getmatrix()
        {
            Console.WriteLine(\"Enter The Number of Rows : \");
            m = int.Parse(Console.ReadLine());
            Console.WriteLine(\"Enter The Number of Columns : \");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine(\"Enter the Elements\");
            for (i = 1; i <= m; i++)
            {
                for (j = 1; j <= n; j++)
                {
                    a[i, j] = int.Parse(Console.ReadLine());
                }
            }
            Console.WriteLine(\"Given Matrix\");
            for (i = 1; i <= m; i++)
            {
                for (j = 1; j <= n; j++)
                {
                    Console.Write(\"\\t{0}\", a[i, j]);
                }
                Console.WriteLine();
            }
        }
      
        public void row(int num)
        {
           int r;
            int i;
            i=num;
            r = 0;

                for (j = 1; j <= n; j++){
                    r = r + a[i, j];
                }

                Console.WriteLine(\"{0} Row Sum : {1}\", i, r);
        }
   }

    class matrowsum
    {
        static void Main(string[] args)
        {
            int num;
            mat ma = new mat();
            ma.getmatrix();
            Console.WriteLine(\"Enter the Row number to get SUM: \");
            num = int.Parse(Console.ReadLine());
            ma.row(num);
        }

    }

}

output:

Hello, I need help with this problem. I\'m using Visual Studio 2015 C# Web Form..... Write a syntactically correct C# method definition called SumRow. The metho
Hello, I need help with this problem. I\'m using Visual Studio 2015 C# Web Form..... Write a syntactically correct C# method definition called SumRow. The metho

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site