-
Notifications
You must be signed in to change notification settings - Fork 18
/
Delete an element in Array at its desired Position(Numbers).cs
48 lines (45 loc) · 1.44 KB
/
Delete an element in Array at its desired Position(Numbers).cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication61
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Removing an Element in Array with index position");
int i, j, k, N,pos;
Console.WriteLine("Enter the Maximum Range of the Array");
N = Convert.ToInt32(Console.ReadLine());
int[] a = new int[N];
Console.WriteLine("Enter the input Elements of the Array:");
for (i = 0; i < N; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("The input Elements are:");
for (i = 0; i < N; i++)
{
Console.Write("{0} ", a[i]);
}
Console.WriteLine("\n");
Console.WriteLine("Enter the Position of the element to be removed");
pos = Convert.ToInt32(Console.ReadLine());
while (pos < N)
{
a[pos - 1] = a[pos];
pos++;
}
N--;
Console.WriteLine("After the element removed values are:");
for (i = 0; i < N; i++)
{
Console.Write("{0} ", a[i]);
}
Console.WriteLine("\n");
Console.ReadLine();
}
}
}