delete from array

Question Description

#include <stdio.h>#define N 10int search(int a[], int n, int value) {    int i;    for (i = 0 ;i < n ; i++ ) {        if (a[i] == value)            return i;    }    return -1;}int main() {    int i;    int length, element, value, array[N];    printf("Enter the length of the array: n");    scanf("%d", &length);    printf("Enter the elements of the array: n");    for (i = 0; i < length; i++) {    scanf("%d", &array[i]);    }    printf("Enter the value for searching: n");    scanf("%d", &element);    value = search(array, length, element);    if (value == -1)        printf("%d", -1);    else        printf("%d", value);    return 0;}

Modify the program so that it deletes all instances of the value from the array. As part of the solution, write and call the function delete() with the following prototype. n is the size of the array. The function returns the new size of the array after deletion (The array after deletion will be the same size as before but the actual elements are the elements from index 0 to new_size-1). In writing function delete(), you may include calls to function search(). The main function takes input, calls the delete() function, and displays the output.

int delete(int a[], int n, int value);

Example input/output #1:

Enter the length of the array: 6

Enter the elements of the array: 4 3 1 0 3 9

Enter the value for deleting: 3

Output array: 4 1 0 9

Get your college paper done by experts

Do my question How much will it cost?

Place an order in 3 easy steps. Takes less than 5 mins.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *