0% found this document useful (0 votes)
2 views2 pages

2

The document contains a C# program that defines methods for finding and deleting an element from an array. The 'findElement' method searches for a specified key in the array and returns its index, while the 'deleteElement' method removes the key from the array if found and adjusts the array size accordingly. The 'Main' method demonstrates these functionalities using a sample array.

Uploaded by

Singh Saab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

2

The document contains a C# program that defines methods for finding and deleting an element from an array. The 'findElement' method searches for a specified key in the array and returns its index, while the 'deleteElement' method removes the key from the array if found and adjusts the array size accordingly. The 'Main' method demonstrates these functionalities using a sample array.

Uploaded by

Singh Saab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

class main

static int find element(int[] arr, int n, int key)

int i;

for (i = 0; i < n; i++)

if (arr[i] == key)

return i;

return -1;

static int delete element(int[] arr, int n, int key)

int pos = find element(arr, n, key);

if (pos == -1) {

Console. Write Line("Element not found");

return n;

int i;

for (i = pos; i < n - 1; i++)

arr[i] = arr[i + 1];

return n - 1;

public static void Main()

{
int i;

int[] arr = { 10, 50, 30, 40, 20 };

int n = arr.Length;

int key = 30;

Console.Write("Array before deletion ");

for (i = 0; i < n; i++)

Console.Write(arr[i] + " ");

Console.WriteLine();

n = deleteElement(arr, n, key);

Console.Write("Array after deletion ")

for (i = 0; i < n; i++)

Console.Write(arr[i] + " ");

You might also like