I am trying to create a program in which the size of the index of the array and its elements will be entered by the user. The program then prompts the user to search for a specific item and displays where it is located.
I already came up with the code:
using System;
namespace ConsoleApplication1
{
class Program
{
public static void Main(String [] args)
{
int a;
Console.WriteLine("Enter size of index:");
a= int.Parse(Console.ReadLine());
int [] index = new int [a];
for (int i=0; i<index.Length;i++)
{
Console.WriteLine("Enter number:");
index[i]=int.Parse(Console.ReadLine());
}
}
}
}
The problem is that I cannot display the numbers entered, and I do not know how to look for an array element. I am thinking about using an if statement.
Another thing, after entering the elements, the program should display numbers, such as Number 0: 1
Is this correct Console.WriteLine("Number"+index[a]+":"+index[i]);:?
And where should I put the expression? after a for loop or inside it?
source
share