Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Cells with Odd Values in a Matrix
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Cells with Odd Values in a Matrix int rows =2; int cols =3; int [,] arr = new int[2,3]{ {0, 0, 0}, {0, 0, 0} }; Display(arr, rows, cols); int[][] indices = new int[2][]; indices[0] = new int[] {0,1}; indices[1] = new int[] {1,1}; for(int k=0; k<indices.Length; k ++) { int r = indices[k][0]; int c = indices[k][1]; // increment val by 1 for all columns for(int i=0; i < cols; i++) { arr[r,i] = arr[r,i] + 1; } // increment col val by 1 for all rows for(int i=0; i < rows; i++) { arr[i, c] = arr[i, c] + 1; } } // display array after increment Display(arr, 2, 3); // get odd vals count int res = 0; for(int rIndx = 0; rIndx < rows; rIndx++){ for(int cIndx = 0; cIndx < cols; cIndx++) { if(arr[rIndx,cIndx] % 2 > 0) res++; } } Console.WriteLine("Number of odd values : " + res); } public static void Display(int [,] arr, int r, int c) { Console.WriteLine(); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { Console.Write(arr[i,j] + " "); } Console.WriteLine(); } } } }
run
|
edit
|
history
|
help
0
https://rextester.com/ZZVYV85848
Generate Secure GUID
Try-Catch-TaskRun
ejemplo c# 2
test
D19
asxsdxsd
Konsol Üçgen Çizimi
Пример применения необязательных аргументов
ANQ Bug with Feb month display