harish reddy

harish reddy

  • 1.9k
  • 162
  • 22.7k

For loop in Array

Feb 12 2018 1:23 AM
Hi,
 
In the code below, why is my Else statement not printing?
.
Alos how can i fid the largest element of any array ?
 
static void Main()
{
int[] firstarray = new[] { 1, 2, 3, 4, 5, 6, 7, 9 };
for (int i = 0; i <= firstarray.Length-1; i++)
{
for (int j = 1; j>=firstarray.Length-1; j++)
{
if (firstarray[i]>firstarray[j])
{
Console.WriteLine(i);
}
else if (firstarray[i] < firstarray[j])
{
Console.WriteLine(j);
}
}
}
}

Answers (7)