Skip to content

Conversation

@Smangumb
Copy link
Owner

No description provided.

// read the string value and convert it in to integer
int n = Convert.ToInt16(Console.ReadLine());
//Reading the values one by one
for (i = 1; i <= n; i++)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember, everything in C# is zero based indexed. So you are actually creating an array with an unused slot.

static void Main(string[] args)
{
int i;
int[] a = new int[30];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you will move this down to below int n = ... you can create an array only as big as you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants