[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

how sum of each row 2D array [3,6]

Write c# programming to the following:
-Initialize two D –array [3,6].
-Read there values from user.
-sum of each row and print the result.
-multiplication of each columns and print the result.
-print out the array as following.
output :
1                   2             3               4               5               6  sum=   21                              
2                   6             5               4               9               7  sum=  33                                    
8                   7             6               5               9               0  sum=  35                                
m=   16       m=  84     m=90      m=  80    m= 405     m= 0      
0
myaspnet
Asked:
myaspnet
  • 2
1 Solution
 
viralypatelCommented:
Here you go:

            // read the values from the user
            string[,] answer = new string[3,6];
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("Enter the values for row " + i.ToString() + " ...");
                for (int j = 0; j < 6; j++)
                {
                    answer[i, j] = Console.ReadLine();
                }
                Console.WriteLine("\n\n");
            }

            //print the values alont with the sum and product
            for (int i = 0; i < 3; i++)
            {
                int sum = 0;
                for (int j = 0; j < 6; j++)
                {
                    Console.Write(answer[i, j] + "\t");
                    sum += int.Parse(answer[i, j]);
                }
                //write the sum for each row
                Console.Write("Sum = " + sum.ToString());
                Console.WriteLine("");
            }
            for (int j = 0; j < 6; j++)
            {
                int prod = 1;
                for (int i = 0; i < 3; i++)
                {
                    prod *= int.Parse(answer[i, j]);
                }
                Console.Write("M = " + prod.ToString() + "\t");
            }

            //write the products for each column


            //pause to view result
            Console.WriteLine("\n\n\nPress Enter to Exit...");
            Console.ReadLine();

Open in new window



Output will show as follows:

Enter the values for row 0 ...
1
2
3
4
5
6



Enter the values for row 1 ...
3
4
5
6
7
8



Enter the values for row 2 ...
1
1
1
1
1
1



1       2       3       4       5       6       Sum = 21
3       4       5       6       7       8       Sum = 33
1       1       1       1       1       1       Sum = 6
M = 3   M = 8   M = 15  M = 24  M = 35  M = 48


Press Enter to Exit...

Open in new window

0
 
myaspnetAuthor Commented:
thank you very mach..
0
 
myaspnetAuthor Commented:
thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now