Question about vector [closed]

0

I'm trying to list the numbers that the user types but I'm not finding the function, can anyone give me a light?

class Program
        {
            static void Main(string[] args)
            {
                int[] atividade = new int[6];
                for (int i = 1; i < 6; i++)
                {
                    Console.WriteLine("Insira o " + i + "° numero: ");
                    atividade[i] = Int32.Parse(Console.ReadLine());
    
asked by anonymous 19.08.2017 / 04:13

1 answer

1

You can use a foreach to do this:

int[] atividade = new int[6];
for (int i = 1; i < 6; i++)
{
    Console.WriteLine("Insira o " + i + "° numero: ");
    atividade[i] = Int32.Parse(Console.ReadLine());
}
foreach(int i in atividade)
{
    Console.Write($"{i}, ");
}

It will go through all the values in the array and write them on the screen.

    
19.08.2017 / 04:19