Respuesta :

Answer:

Create an integer array which holds five integers

Explanation:

I have written a simple program using c# as a programming language.

Here's  the  program:

using System;

public class Test

{

   public static void Main()

   {

       int[] numbers = new int[5];

       Console.WriteLine("enter 5 numbers");

       for (int i=0; i<=4; i++)

       {

          numbers[i]= Convert.ToInt32(Console.ReadLine());

       }

       foreach(int k in numbers)

       {

           Console.WriteLine(k+ "\n");

       }

       Console.WriteLine("----------------------------");

       Console.WriteLine("In reverse");  

       for(int j=4; j>=0; j--)

       {

           Console.WriteLine(numbers[j] + "\n");

       }

       Console.ReadLine();

   }      

}

Explanation of Program:

I have created an array named "numbers"  and assigned 5 as it's fixed size.

I prompted the user to enter numbers up to 5. I read those input numbers using Console.ReadLine() and converted to integers as return type of  Console.ReadLine() is string. I have stored all inputs from user into an array  while reading as below:

    numbers[i]= Convert.ToInt32(Console.ReadLine());

Next step is to print them. We can do it easily using foreach loop where it pulls out elements from an array until it reaches  end of an array and print them on console.

If I need to print them from first to last, the condition is,

    for (int i=0; i<=4; i++)  

as it needs to start from first element

If I need to print them from last to first, the condition is,

    or(int j=4; j>=0; j--)  

as it needs to start from last element

The application that can hold five integers in an array and display the integer from first to last and last to first is as follows;

integers = [15, 17, 8, 10, 6]

print(integers)

x = integers[::-1]

print(x)

Code explanation:

The code is written in python.

  • The first line of code, we declared a variable named integers. This integers variables holds the 5 integers.
  • The second line of code, we print the the integers from first to last.
  • The next line of code, we reversed the array from last to first and stores it in the variable x.
  • Then, we print the x variable to get the code from last to first.

learn more on array here:https://brainly.com/question/19587167

Ver imagen vintechnology