answersLogoWhite

0


Best Answer

Enter how many elements you want to enter: 4

Enter the array elements:

10

20

30

40

Enter the location, where you want to delete: 3

Deleted value : 30

The new element list: 10 20 40

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

/*

Removes the idx'th element from "list", an array of integers.

-- not tested --

Note that this routine assumes that the last element in the array has a null value.

*/

void dropElement(int *list, int idx){ int n;

for(n = 0; n < idx && list[n] != null; n++);

for(;list[n] != null; n++){list[n] = list[n + 1];}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to delete an array element in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Will an array element be deleted when you retrieve it from the array?

You cannot delete from an array.


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i &lt; array.length(); i++) { if(array[i] &gt; max) max = array[i] } return max; }


How are arrays processed?

Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.


What is the algorithm using c to delete duplicate elements from an array?

To detect the duplicate, you will have to write a nested loop that compares each element with all the previous elements.To actually delete the duplicate, once you find it, you have to move over all the elements after the duplicate. If the order of the elements doesn't matter, it is faster to just move the LAST array element, overwriting the duplicate element. Use a variable to keep track how many elements of the array are "usable". For example, if your array had 10 elements, and you delete 1, the array size will still be 10... but (after moving the elements over) only 9 of those elements have useful information.

Related questions

Write an Algorithm to delete a last element from the array?

// Assuming you dynamically allocated this array using "new"... delete array[arraysize - 1]; arraysize--;


Program in c to delete an element in sorted array?

You cannot delete elements from an array. But you can move the elements: if (del_index &lt; no_of_elements-1) { memmove (&amp;array [del_index], &amp;array [del_index+1], sizeof (array [0]) * (no_of_elements - del_index - 1)); } --no_of_elements;


Will an array element be deleted when you retrieve it from the array?

You cannot delete from an array.


Delete an element from an options array?

Set it to null


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i &lt; array.length(); i++) { if(array[i] &gt; max) max = array[i] } return max; }


Write a program to delete an array element?

#include &lt;stdio.h&gt; #include &lt;conio.h&gt; #define size 10 void main() { int a[size],del,j,i; clrscr(); for(i=0;i&lt;size;i++) {j=i+1; printf(" Enter the %d element of array",j); scanf("%d",&amp;a[i]);} printf(" Enter the element to be deleted"); scanf("%d",&amp;del); del--; for(i=del;i&lt;size-1;i++) a[i]=a[i+1]; a[size-1]=0; printf(" Element has been deleted"); printf(" Array now is..... "); for(i=0;i&lt;size;i++) printf("%d ",a[i]); getch(); }


How are arrays processed?

Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.


What is the algorithm using c to delete duplicate elements from an array?

To detect the duplicate, you will have to write a nested loop that compares each element with all the previous elements.To actually delete the duplicate, once you find it, you have to move over all the elements after the duplicate. If the order of the elements doesn't matter, it is faster to just move the LAST array element, overwriting the duplicate element. Use a variable to keep track how many elements of the array are "usable". For example, if your array had 10 elements, and you delete 1, the array size will still be 10... but (after moving the elements over) only 9 of those elements have useful information.


How do you write a program which reads a list of ten numbers and print the list in reserve order in c program?

The simplest way is probably to read the numbers into an array and then prints each element of the array starting at the last one and moving backwards.


Write a program in c to find the largest no out of a matrix of order mn?

/* using ellipses (...) to indicate tabs for clarity */ double largest (double *array, int M, int N) { ... int i, j; ... double *element; ... double answer = array[0][0]; ... for (i=0; i&lt;M; i++) { ... ... for (j=0; j&lt;N; j++) { ... ... ... element = array + i*M + j; ... ... ... if (*element &gt; answer) answer = *element; ... ... } ... } ... return answer; }


Write a program to find out the address of an element in an array?

== Java does not allow reference to memory locations. == In C: for (i=0; i&lt;n; ++i) printf ("a[%d] is at %p\n", i, &amp;a[i]);