Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- var matrixTxT = File.ReadAllText(@"E:\Downloads\ChromeDownloads\matrix.txt");
- var str = matrixTxT.Split(new char[] { ' ', '\n'}, StringSplitOptions.RemoveEmptyEntries);
- string[] wordsArray = matrixTxT.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
- foreach(string word in wordsArray)
- {
- Console.Write(word+" ");
- }
- var rows= File.ReadAllLines(@"E:\Downloads\ChromeDownloads\matrix.txt").Length;
- var cols =(str.Length/rows);
- int i = 0 , k = 0;
- int[,] matrix = new int[rows, cols];
- Console.WriteLine($"\nRows:{rows} Cols:{cols} Items:{str.Length}");
- foreach (var row in matrixTxT.Split('\n', StringSplitOptions.RemoveEmptyEntries))
- {
- k = 0;
- foreach (var col in row.Trim().Split(' '))
- {
- matrix[i, k] = int.Parse(col.Trim());
- k++;
- }
- i++;
- if (i == rows)
- {
- break;
- }
- }
- int evenSum = 0;
- int oddSum = 0;
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- if (col % 2!=0 && matrix[row, col] % 2 !=0)
- {
- oddSum += matrix[row, col];
- }
- else if(row % 2 == 0 && matrix[row, col] % 2 == 0)
- {
- evenSum += matrix[row, col];
- }
- }
- }
- Console.WriteLine($"Even numbers sum: {evenSum}\nOdd numbers sum: {oddSum}");
- }
- }
- }
Add Comment
Please, Sign In to add comment