3
I’m having a problem on line 18 of this code that says:"There was an untreated "System.Indexoutofrangeexception" exception in Consoleapp19.exe The index was outside the matrix boundaries.
How to solve?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp19
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int[] x = new int[n];
int contPar = 0, maior = 0;
for (int i = 1; i<= x.Length; i++)
{
x[i] = int.Parse(Console.ReadLine());
if(x[i]%2 == 0)
{
contPar++;
}
if(x[i] > maior)
{
maior = x[i];
}
}
Console.WriteLine("O maior número é {0}", maior);
Console.WriteLine("Existem {0} n°s pares", contPar);
}
}
}
Vectors start from Intel Zero. The problem is in the for header:
(int i = 0; i< x.Length; i++)
– Francisco