Home c# C #. Create an array of 10 numbers. Calculate the amount of...

# C #. Create an array of 10 numbers. Calculate the amount of odd array elements

Author

Date

Category

I tried to do it manually pointing all 10 variables in the array. Now I do not know how to withdraw the amount of odd items. Help please.

Code:

``````int [] a = new int [10];
int a = a [0];
int b = a [1];
int c = a [2];
int d = a [3];
int e = a [4];
int f = a [5];
int g = a [6];
int h = a [7];
int i = a [8];
int j = a [9];
Float S = 0;
Console.WriteLine ("Enter A");
Console.WriteLine ("Enter b");
Console.WriteLine ("Enter C");
Console.WriteLine ("Enter D");
Console.WriteLine ("Enter E");
Console.WriteLine ("Enter F");
Console.WriteLine ("Enter G");
Console.WriteLine ("Enter H");
Console.Writeline ("Enter i");
Console.WriteLine ("Enter J");
``````

Arrays and cycles, cycles and arrays. If you have an array in the initial stages of training, but there is no cycle, it means that something went wrong.

``````int [] a = new int [10];
for (int i = 0; i & lt; a.length; i ++)
{
Console.Write (\$ "enter a [{i}] =");
a [i] = int.parse (Console.ReadLine ());
}
int sum = 0;
for (int i = 0; i & lt; a.length; i ++)
{
IF (A [I]% 2 == 1)
SUM + = A [I];
}
Console.WriteLine (\$ "amount of odd numbers = {SUM}");
``````

And there is a LINQ version

``````int [] a = enumerable.range (0, 10)
.Select (i = & gt;
{
Console.Write (\$ "enter a [{i}] =");
}). Toarray ();
int sum = a.where (x = & gt; x% 2 == 1) .sum ();
Console.WriteLine (\$ "amount of odd numbers = {SUM}");
``````

To begin with, you incorrectly read the array. It is necessary to Console.Read (A [I]), the I-index of the element. In order to determine whether the element is odd, it is necessary to divide it to 2 and see whether its residue is equal to 1. A% 2 == 1

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.