Advertisement
skipter

C# Array - Count the Odd Numbers at Odd Position

Jun 16th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApp9
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             var numbers = Console.ReadLine().Split(' ');
  9.             var findTheOdd = new int[numbers.Length];
  10.             for (int i = 0; i < numbers.Length; i++)
  11.             {
  12.                 findTheOdd[i] = int.Parse(numbers[i]);
  13.             }
  14.             int oddCounter = 0;
  15.             for (int i = 0; i < findTheOdd.Length; i++)
  16.             {
  17.                 if ((findTheOdd[i] % 2 == 1) && (i % 2 == 1) || (findTheOdd[i] % 2 == -1) && (i % 2 == 1))
  18.                 {
  19.                     oddCounter++;
  20.                     Console.WriteLine($"Index {i} -> {findTheOdd[i]}");
  21.                 } else
  22.                 {
  23.  
  24.                 }                
  25.             }            
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement