Advertisement
BloodMoonYTC

soroszlopsum

Oct 24th, 2021
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. using System;
  2.  
  3. namespace sorokesoszlopok
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int i, j, n;
  10.             int[,] arr1 = new int[10, 10];
  11.             int[] rsum = new int[10];
  12.             int[] csum = new int[10];
  13.  
  14.             Console.Write("\n\nFind sum of row an column of a Matrix:\n ");
  15.             Console.Write("-------------------------------------------\n");
  16.  
  17.  
  18.             Console.Write("Input the size of the square matrix : ");
  19.             n = Convert.ToInt32(Console.ReadLine());
  20.  
  21.             Console.Write("Input elements in the matrix :\n");
  22.             for (i = 0; i < n; i++)
  23.             {
  24.                 for (j = 0; j < n; j++)
  25.                 {
  26.                     Console.Write("element - [{0}],[{1}] : ", i, j);
  27.                     arr1[i, j] = Convert.ToInt32(Console.ReadLine());
  28.                 }
  29.             }
  30.             Console.Write("The matrix is :\n");
  31.             for (i = 0; i < n; i++)
  32.             {
  33.                 for (j = 0; j < n; j++)
  34.                     Console.Write("{0}  ", arr1[i, j]);
  35.                 Console.Write("\n");
  36.             }
  37.  
  38.             /* Sum of rows */
  39.             for (i = 0; i < n; i++)
  40.             {
  41.                 rsum[i] = 0;
  42.                 for (j = 0; j < n; j++)
  43.                     rsum[i] = rsum[i] + arr1[i, j];
  44.             }
  45.  
  46.             /* Sum of Column */
  47.             for (i = 0; i < n; i++)
  48.             {
  49.                 csum[i] = 0;
  50.                 for (j = 0; j < n; j++)
  51.                     csum[i] = csum[i] + arr1[j, i];
  52.             }
  53.  
  54.             Console.Write("The sum or rows and columns of the matrix is :\n");
  55.             for (i = 0; i < n; i++)
  56.             {
  57.                 for (j = 0; j < n; j++)
  58.                     Console.Write("{0}    ", arr1[i, j]);
  59.                 Console.Write("{0}    ", rsum[i]);
  60.                 Console.Write("\n");
  61.             }
  62.             Console.Write("\n");
  63.             for (j = 0; j < n; j++)
  64.             {
  65.                 Console.Write("{0}   ", csum[j]);
  66.             }
  67.             Console.Write("\n\n");
  68.             Console.ReadLine();
  69.         }
  70.     }
  71. }
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement