Write a program in C# Sharp to find the sum of left diagonals of a matrix

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to find the sum of left diagonals of a matrix.
Test Data:
Input the size of the square matrix : 2
Input elements in the first matrix :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
The matrix is :
1 2
3 4
Addition of the left Diagonal elements is :5

الأجوبة

using System;  
public class Exercise24 
{  
    public static void Main()
   {
     int i,j,sum=0,n,m=0;
	 int[,] arr1 = new int[50,50]; 
       Console.Write("\n\nFind the sum of left diagonals of a matrix :\n");
       Console.Write("--------------------------------------------\n");	  
	 Console.Write("Input the size of the square matrix : ");
	 n=Convert.ToInt32(Console.ReadLine());
         m=n;
	 Console.Write("Input elements in the matrix :\n");
       for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
	           Console.Write("element - [{0}],[{1}] : ",i,j);
	           arr1[i,j]=Convert.ToInt32(Console.ReadLine());
            }
        }  
	 Console.Write("The matrix is :\n");
	 for(i=0;i<n;i++)
	 {
	   for(j=0;j
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...