desislava_topuzakova

2. Средноаритметично по редове

Mar 20th, 2021
1,311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Arrays
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int rows = int.Parse(Console.ReadLine());
  12.             int cols = int.Parse(Console.ReadLine());
  13.  
  14.             int[,] intMatrix = new int[rows, cols];
  15.  
  16.             for (int row = 0; row < rows; row++)
  17.             {
  18.                 for (int col = 0; col < cols; col++)
  19.                 {
  20.                     intMatrix[row, col] = int.Parse(Console.ReadLine());
  21.                 }
  22.             }
  23.  
  24.             for (int row = 0; row < rows; row++)
  25.             {
  26.                 int sum = 0;
  27.                 for (int col = 0; col < cols; col++)
  28.                 {
  29.                     Console.Write(intMatrix[row, col] + " ");
  30.                     sum += intMatrix[row, col];
  31.                 }
  32.                 //сумата на реда
  33.                 double average = sum * 1.0 / cols;
  34.                 Console.WriteLine(average);
  35.  
  36.             }
  37.        
  38.         }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment