This question has already been answered:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp66 { class Program { static void Main(string[] args) { int sum = 0; Console.WriteLine("Enter the dimension of array: "); int a = Convert.ToInt32(Console.ReadLine()); int[] A = new int[a]; for (int i = 0; i < A.Length; i++) { Console.WriteLine("Enter the number: "); A[i] = Convert.ToInt32(Console.ReadLine()); } for (int i = 0; i < A.Length; i++) { if (A[i] % 2 == 1) { sum += A[i]; } } Console.WriteLine("Sum of all no paired elements of array - {0}", sum); } } } 

Reported as a duplicate by Grundy , D-side , default locale , 0xdb , VladD c # Mar 24 '18 at 18:17 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    "unpaired" - is it odd? "negative" - ​​is it negative? Add sample input and expected result. - Igor
  • Program execution example: Enter the 1st element of the array: 15 Enter the 2nd element of the array: 2 Enter the 3rd element of the array: 4 Enter the 4th element of the array: -7 Enter the 5th element of the array: 9 Enter the 6th element array: 24 ----------------------------------------------- --- ----------- Array: 15 2 4 -7 9 24 The sum of odd elements of the array: 17 - Sasha R
  • Check what is A[i] % 2 for negative A[i] . - VladD

1 answer 1

Because you need to take A[i] modulo. Because the result may not be 1 and -1