Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Cells with Odd Values in a Matrix
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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(); } } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,3 sec, absolute running time: 0,19 sec, cpu time: 0,16 sec, average memory usage: 15 Mb, average nr of threads: 3, absolute service time: 0,52 sec
edit mode
|
history
|
discussion
0 0 0 0 0 0 1 3 1 1 3 1 Number of odd values : 6