# Program in C# to count odd elements of a 2D array Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 494
Suppose we have a 2D array

`{  {1,2,3,4},  {5,6,7,8},  {9,10,11,12},  {13,14,15,16}}`

We need to find the count of odd elements of the 2D array. The below program will do so

`using System;using System.Collections.Generic;using System.Linq;namespace ConsoleApplication2{    class Program    {         static void Main(string[] args)        {	    int oddCounter=0;            int row = 4;            int col = 4;            int[,] matrix = new int[4, 4] {                                            {1,2,3,4},                                            {5,6,7,8},                                            {9,10,11,12},                                            {13,14,15,16}                                          };            for(int i=0;i<row;i++)            {                for(int j=0;j<col;j++)                {                    if (matrix[i, j] % 2 != 0)                       			oddCounter++;                }            }	    Console.Write("Number of Odd Elements in the matrix : " + oddCounter);            Console.ReadKey();        }     }}Result--------Number of Odd Elements in the matrix : 8`
{"ft_lang_label":"__label__en","ft_lang_prob":0.5275916,"math_prob":0.9631762,"size":694,"snap":"2020-10-2020-16","text_gpt3_token_len":245,"char_repetition_ratio":0.10144927,"word_repetition_ratio":0.074074075,"special_character_ratio":0.43659943,"punctuation_ratio":0.29787233,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97636664,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-28T11:58:49Z\",\"WARC-Record-ID\":\"<urn:uuid:c3b2654f-d7b2-49cc-a4b9-85a8b708d8e3>\",\"Content-Length\":\"37322\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c00873f0-da03-4c48-b08e-cb12fa64e045>\",\"WARC-Concurrent-To\":\"<urn:uuid:975add1b-503a-4f45-90f8-498b64922be9>\",\"WARC-IP-Address\":\"23.239.203.17\",\"WARC-Target-URI\":\"http://www.dotnetfunda.com/codes/show/7963/program-in-csharp-to-count-odd-elements-of-a-2d-array\",\"WARC-Payload-Digest\":\"sha1:TVGCEULLRUZZQFHXZYH2TIMLZWMUSE3D\",\"WARC-Block-Digest\":\"sha1:C4BWP6IVXEAO4VTRGW7O2G2OEIY6JMM3\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875147154.70_warc_CC-MAIN-20200228104413-20200228134413-00350.warc.gz\"}"}