0 like 0 dislike
2.1k views

Write a function delete_e(int arr[],int size,int position) that delete an element from an array. Deleting an element does not affect the size of array. It is also checked whether deletion is possible or not, For example if array is containing five elements and you want to delete element at position six which is not possible.

The function returns 1 if success and 0 if fail (impossible value for position).

The first input is the number of elements in array (3); The array values follow; The input end with position of the element need to be deleted.

``````#include <stdio.h>
int delete_e(int arr[],int size,int position)
{
/*INSERT YOUR CODE HERE*/
/*在這裡寫你的程式*/

/*END OF YOUR CODE*/
}

int main(void)
{
int array[100], position, c, n;

scanf("%d", &n); //Enter number of elements in array
for ( c = 0 ; c < n ; c++ )     //Enter array
scanf("%d", &array[c]);

scanf("%d", &position);         //Enter the location where you wish to delete element

if (delete_e(array,n,position)) //If delete success then print the result
for( c = 0 ; c < n - 1 ; c++ )            //Print the result array
printf("%d ", array[c]);
else printf("Impossible position!");             //If fail

return 0;
}``````

Please complete this program by only insert your code between those tags:

/*INSERT YOUR CODE HERE*/
/*END OF YOUR CODE*/

Example input:

``````3
4 7 8
1``````

Example output

``7 8``

Remember: You may correct the cases, but your code always be revised!

[Exercise] Coding (C) - asked
edited | 2.1k views

0 like 0 dislike
`Hidden content!#include * **    *  *  * int delete_e(int arr[],int size,int position){      *** * * ***** **  ****** *  ** *   *             *     * ******* * *** ***** * ** *  * * ** *   0;  ******* ** **  * **  * ** **    *  * * *      *  * ******** * ** *   * ***** * * *   ** **  ***     *    ** *** *   ** **  ** * *** * *       * *  ** * **** * **** ** * ***     **            ** **   *****  * *  * *      ** ***** **     *  **  * *  1;}int main(void){** * ***   ***  **  array[100], position, c, n; *    * *  *  ** * **** **   ** ** &n); //Enter number of elements in array   ***  * *   ** * *  * ( c = 0 ; c < n ; c++ ) ** *   **  ***  ** *    *** array***  * *  *** **   ***  ***  **       ** * *    **** ****   ** ***  *  ** *  ******* *** *** **  *  ** ** **  * ******  **       **      * * * * **   ** *****  ***       **   * *  * * the location where you wish to delete element *          *****  *  *   ****   *    * * *  //If delete success then print the result* * ***    **    ***  *  *  **** *      *  c = 0 ; c < n - 1 ; c++ )   ** *  *** *  *** *   *   ****  * * *    ** * *   *** *  **    * ***        ** ***  ** * the result array **  *   **** * *     *  *****   **** * *****     *   **    *  ****      ***  ** *** **    * ", array[c]);  * **   *  * ** ** * ** * *** *****   **   * * *        * ** * * **        *  * * ** ** *** * *****  ** *  ****      *******    **  * fail    * * *  ***  **   * * 0;}`
answered by (-140 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include  * * ***  *   ***int delete_e(int arr[],int size,int position){**  * * ***  ***     * * ** *     * * *  * * * * ****    * ******** *  * ****  ** **  ** *   ** * 0; ***  ***   * *      * *    *   ***   ******  *    **** *  * **  * * **  **    ** ***  *** *   ** ***  *  **  *  * *   * * *   *** * *  ** * *    ***     *  ****  *  ***** *** *     *** *  **  * ** ***** ***  *  *   ** *    * * * * **   1;}int main(void){* ***   *****  ** * *  array[100], position, c, n; * *** ***  *  ** ***  * ****    ** *   &n); //Enter number of elements in array *   * ***  * *   * **  ( c = 0 ; c < n ; c++ )   *    *** *       ** * *    *** * array  **  ** *   ** *  ** ***    * ****  *****  ** ****    ******  *   * * * ***  *      **  * ***  *  *   *     * ****** * ***      *   * *   * *******    **   *** ** *    ***      ** the location where you wish to delete element  * * ** *  * * *      *  ***  * *  *  //If delete success then print the result***** ** **  *  *  *  *  * **  **  *** * ***    * * ** c = 0 ; c < n - 1 ; c++ ) *    ***  **** *   * *    *******  *   *** * * ****   **  * *  * *  * ** *   the result array****** **** ***** * * * *    **   ** ** * * * *    *    *  *  *** ** **  ****  * **  *  **** ***   * * ", array[c]);* * * ***** * * * * * *** *    * *****    *     ** * * *   * **  * * *  *   *  * *   *  *** *****    ***** *** ****   **  **  ** *   **      * * * ****** ** fail  * *****  ** *    ** **   *  0;}`
answered by (-16 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include *** **    ** *   *int   ** *  arr[],int size,int position){***      **    **   * *   ** *  *  i;*  ***  * **** ***    * ****  *** * ****  ||  ** **  *** ***   ******* *  else{   ****  **** ***   *  *  ** *** *   * ******* i++)  *  **   **  ** **     * * *****   **   ** *   * *** * * **    **  **    **   ** *   = arr[i + 1];* *      ***  *  * * ***  ******** * * *      ** *  ********}}int main(void){   *****  **  **   *  *******  ** ** array[100], position, c, n;  * ** ********   **   *   *   * *  *   **  *    ** //Enter number of elements in array** *** *    * **** *   *   ** ( c = 0 ; c < n ; c++ )     * *   * * **  * * *  * **  ** array   *******  * ** **     **    * **     * ** ***   **  *  **  * ** *** *** *  * *  ** *   ***     ******** * ** *     *  *   *** *   * * **  ***  * ** ** **  ** **  **  ** ***** ****   * * ****  ***  ** ****** the location where you wish to delete element   *      *** * **  ***     *  *       * ** //If delete success then print the result   *** ** *  **  *** *   * *  *    *    *  **   * c = 0 ; c < n - 1 ; c++ ) *   * *      ***    * * * *** *  **   ** *  *        * **   * * * **    *   * **  * the result array   **  * *   **     * * ****** * *  * *  **  *  *  *** * *  *   **      **** * ** *  * *  ** ", array[c]); *****  ** *****   * ***     * **   *** ***     * **   ****   *  *** * **  *  *** ***  *****  ** *  *** *** **    *** * ** *  **     * ***   ***    ** fail ** **     * *  *    ** ** *   *  0;}`
answered by (-168 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include * ** *  ***** * int delete_e(int arr[],int size,int position){ **  ******** ******  * * ***   i;*** *  **** ***    ****** *   * ( position >= size+1 ) *  * *        *  * * ** * *       ** ***** ****** *** ***  * 0;** **     ** * * * *   *** *  *    *   *** ****    ** **  **    **  ***** ***     ***  *   ***** ** *      * *  *  * ( i = position - 1 ; i < size - 1 ; i++ )* *     *   * ***    ** **  * **  ****    *  **  **      ********   *** * ** * * = arr[i+1]; * * *   *       * * *     *  ***    * * ******       1; *     *** **  * * *   * ** ** **     **  *   * ** * * * ****   0;}int main(void){*   **** **  *  *    ** array[100], position, c, n;  *** * * *       * * * **  *  **      **      * *    *** *     **  &n); //Enter number of elements in array **    * *  *     *  * **  ( c = 0 ; c < n ; c++ )  ******  ***   **    * * ** * array**  * * ********* *   *  *    ***   * * ***** **      * **** * * *  *** ** *  * ** * * * * **  *  * * * *****  **  *  **  * *   * * **  * *   **** ***  *  ** *** *   ****  *****  * ***  * **  * *        *  *  *      *   ** ** *** * ***** the location where you wish to delete element  * **   **   * *** **** * **  * * *    ** *  ** * *    * **  *    * //If delete success then print the result  * ****** ***  * * ***  * ***  ** * * ** * ****** c = 0 ; c < n - 1 ; c++ ) * * *  **  ****** *** **   *    * *  * **   ***  ****   **   **   * ** **  the result array   *    **    *   ** * * *    * **  ** ***     ** *  **  **** *      ** * * **    *  *** *  *  ", array[c]); *     *** * *  ** *** * ***     * *     ****** *  * *  **  *    *** ** * *** *  * ****  * * *       * *****   *  *    * * **   ** *        **  *    fail* ***    * *** **   *   *  *   * ** *  * ***  ** * * **   *  * 0;}`
answered by (323 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include     **  * ***int delete_e(int arr[],int size,int position){     * ****  * ****** *  *       * ***  ** ***     **     *** **  **        *  * *  *      ** *   * ** ****  1;* *  * ***  **** *   ** *  **   *    ****** ***  * *  * ***   * ****  **  *  * * **    *  *    ***** * *  * *  ** * *****   * 0;*  * **  * ***  **  }int main(void){* * *  *  * ***  **   array[100], position, c, n,m;*  *** **  * **   **  ***   * * **** * &n); //Enter number of elements in array* **  *  **    *   ( c = 0 ; c <= n-1 ; c++ )* *  ****  *  *         * *   *****     * *   *    ** * array** * ***   * ******* ***  *    * ********  ** *   *  * * * &array[c]); *** *  ** * ***   * ** * *  *   ** * *  * *    **** * ***  *** &position);    * * *  ** ****     * **    * *   *  **  ** * *   **** ***  the location where you wish to delete element* ** * * ** *  *    **   * *   * *  * *   *** **  ** * ** * *** *   **  * //If delete success then print the result*    * ** ****  * *  *  *  * ** *** * * **  *   *  ** *  c = 0 ; c <= n - 1 ; c++ ) * ** * ** * * *  ** * ** * ***  * *  *   **  ** ** **    * *** **  ***     *   *** * *   *  * * ****  ***  * * *    ******   ***  the result array    *    ***     * * *****  * *  * *  ** * * *  *     **   * **  ***** *******   *  ** **   ******** *** ***********   * ** * * *** ***  **     *   * *** *    * * ** *  *** * (m!=position) *  **  **    *     *  ***     **     *** *** ****  *  *   *** *  ** * *   * * *** ** **  ** ** *** * *** *  *******   * ****    * * * **  *  **  * ", array[c]); *  **     * **  *    *   ** * *    ** ** *  *    **     ****   *****      **   *    ** *** * *    **  * *  **  ** *  *     *  * *** *   *  * ** ** **  *  * *  position!"); }   * ** **  **  * * ***   * *   ** ***** * *  ***** * *** * * ***** * ** * ** *  * *  fail**    * ***    *  *****   0;}`
answered by (-168 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include   ** ** **    *int *    ***** arr[],int size,int position){   *  **** **** ***  *  * YOUR CODE HERE*/***** **  **  *   * * * ** **   ****** ***   *  * * ** **   *  *** *  **** ****    return 0; *     ** *   *   **  *   *  *    **   i;** *** *** * **     * *** **     **  **    * *    * ****  ** * **   * ****   *** *****        **    *   **   ***** ** ***  * ** * ***        **   * ** * 1;*  *****  *   *   * OF YOUR CODE*/}int main(void){* ***     ****   ** * *  **  *    position, c, n;  * *  **  * *** ***   *  * * * *** **  *   **  *  //Enter number of elements in array***   *** **  *     ( c = 0 ; c < n ; c++ ) * ** *   **** ******** * *** array* * ** ********  ** *    * *  **  * ** ** *   *** *****  *   **    * ***   *       *  * **   **** **    * * *       * * *****  **  ** ******* *  * *    *   *   ** * **** **   ****  * *    *** the location where you wish to delete element*      * * *  **** *  ***  **       *  **  ***  **   * * ** //If delete success then print the result*  ** ** * ******  **  *     * * **  * * **  **  c = 0 ; c < n - 1 ; c++ ) **  *  * ** ** *   ** *  *     ** * *****  **  ****     ***  ****   ***  *  * the result array*  ** * *      ****** * *       * **   *** **  * **        *   * * * * ** *****  *   ****** *      *  *   *    ***    array[c]);    *  ****** ***      *** ***** **  *      **  **   * **  **  ***  **    *** *   *   *  *   *  * **** *      *  * ** ***   * *      ** *  * *   * **** fail* * *  * *      *****    * 0;}`
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include ** **** *  ** ** int  ** ***** arr[],int size,int position){***  ****  ** * ** * ** * YOUR CODE HERE*/*****     ** *   ** ** *   i;  *   ** *    **  * ** *    || *  * *  *    *   * ***** *  * * **     * *    **** **  * ** **    return 0;***   ****   *  *** ** * **  * ***  ***  *  ***  **  ***   *   ** *   ***********  *    *** **       * *  ***   *   * *  *  * i++) ***** ** ****   * * *  * * * ***  *** ** ** ** *****  * * **     *    ****  *  * * *   * * * *   *       *  *** **  ** *     ***  * *** * **   ***   *   = arr[i + 1];     **** * **  ** *  ** * ***    *** *  **  **         size--;    *   ***  *       **     **   * **    ***  *  * ****** i++) *     * ** *****  * ** ** ****   *  *  * *  * ** ***** ** ***  ****   *   ***  **    * arr[i];* * ***  ** * * * **  *  **   * **  * ****  *  * **** *  OF YOUR CODE*/}int main(void){   * *   *  *** **  *   * *  position, c, n;  *  *  **  **** *  **  *** *  ***   **  *   *  * //Enter number of elements in array** *  * *   **     **** ( c = 0 ; c < n ; c++ )    ** * *      **   *  *** array*** ******   * **  *  *****   ** ** *   **  ***  *   *     *  * * **  * **  *    **   *** * *  * ***      *   ** *        *  * * ***   *     ******* * ** *  **   * **  ** ***  *** **  * ** * ** the location where you wish to delete element *         * * **     * *  * * *** * * **   * **  *  ** *** ** //If delete success then print the result   **  *    ** **  ***** **  ** ** ***** * *     c = 0 ; c < n - 1 ; c++ )  **  *  **    * *         * **    *  *  **  * *** *    ***  ** ** * *  * **   the result array *    * ** * *** *   *  *   * ***   ** *  *    *** ***** *  *      *   * * **  * **  **  * *** * ", array[c]);*     *  ****  **  ****          **     **   * * * **  *   *     * ************* **   *** *     ***   ** *   *     *    *        *** * ** *  * fail  *** *  *  **  *   *  **   * ** 0;}`
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include  **   *  *   * int delete_e(int arr[],int size,int position){***      **    * **** *   *  **** *** YOUR CODE HERE*/****** *** **** *    **  ** i; *   *  ******  * * *       **  **  < 0 || position > size)*******    **********  ** *******  * **     ***    *  **  0; ***     ** ****** * * **  **** ***   * *  **  *  **    ** **  * ****  *  *** ** ***** ***  position-1; i<size; i++){*** *     *  ***  *    * * * *  *  ** **  * * * ******    *      *  ** *  ***  * *   = arr[i+1];*   ** **** *  * ** **** * ** ** ** *  ******  ****   ****** * **   *******   *** *   *** ** **  ***   *  **   *** -=1; *  *** *  ** * *       *   *****  **   ** ***  **  ***  *   1;* ** **  ***   ** * ****  **  **     *   * ** *  *** ******* * OF YOUR CODE*/}int main(void){    ** ** **   *  * * *   array[100], position, c, n;*         ** * * *      *** * ****   *  **      *   * ** ** *  ** *  &n); //Enter number of elements in array* ** * ****   ********* ( c = 0 ; c < n ; c++ ) * ******* * ***   *  * * array*   *    * ** * * * ******** ** * *   *  ** ****   *  * * *    *  ****     ***  **     *  *  * **  * * * *  *  * * *   ***   * * ** * **  * **  ** * ** * *  ** * *** * *   *  * **      * **    * ** * ***  * * *      *  **   **** *  * the location where you wish to delete element *   * ***** *** *  ***  ***  * ***    *  * ****     ********  * **     //If delete success then print the result ** * ****   **** ** **  **    *  *   **** * * ***** *   *  *  c = 0 ; c < n - 1 ; c++ )    * * * *  *  ** * *    *****  *  *    * *    ******   *** *** ** *  * ***  * *    the result array ****   *** * *** * **  *    **  *****   **    **   *  *           *   **** * **** * * * **** * *  ", array[c]);  *   *** *** ** **** * ***  *  * ***** ** * ***    ** ***** *  * ** *  ***** * **  ** *  *    **  *    ** *** ***  ** *  *   *    ** * ****  * **    * fail*  *  * *    *** * * *  * * *     ** *  ** *  ***       *  * * 0;}`
answered by (-233 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include <stdio.h>int delete_e(int arr[],int size,int position){***  *  **  **   * *   *  *     i,temp; * **  ******  ** * ** * ** *     ** * ****  ***  ***  * **** *       * **** **   *  ** ** *  * 0;* ** *        * **   *  ** **        *****    *   **  ***** **       *  *     **  *****   * * ** * *****  * * *****    * *  *    *  *  * * * ****  **** *** ***  ** *   *       **  **   ** ***    * **   * **** ****  *****  ****    ***  *    ** *   ** **    * ** **  * * *** ** * **  *  *  *      * ******   ** * * * * ***  **   * * *  ** ** *** **  **    **** **  **  **  **   ***  1;}int main(void){ * *  ** *  *** *   ** * * array[100], position, c, n; * * **  ** **  ** **  * **          &n);    *   *   *       *       ( c = 0 ; c < n ; c++ )    **      *** **** *  *** *  *  ** * *   * ********* **  *** **** ***** *    ** *  * &array[c]);     **   *    *  ** **  **   *** *   &position); * * ****   * * * * * *** *  *   ** ** ***** **     **  * *  *** * * ** *  **   (delete_e(array,n,position))  ***  *********    ** **** **  *    ** ** **  * * * * * c = 0 ; c < n - 1 ; c++ ) ***** ** **  * **   *    ** *    *   *  * * **  * * ***   ***** *   ** ** ***  *****   * ** **** **  *   ***  ** *  *** * * *  **   ***    **  * **  *   * * *** * *****   ", array[c]); ** ***** ***     * printf("Impossible position!"); ** *   ** ** * *   **** * **  **   * *  *   * ******  **    *  ****       *  **    *  *   *  **  *  *   *   *  0;}`
answered by (-284 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
`Hidden content!#include <stdio.h>int delete_e(int arr[],int size,int position){    *  ** ** *** * *****     i,temp;***       * ** **  * * *** *   * *** * ** ***** *   *   ** *  **   *   *       * **  * *** **  0;*   ** ** * * *  *       ****  ***  ******  ***  *** **   * *   ** *    ** **** * * *** ****   *    *  **  ******  ** ** *** * *    *** ******   **       * *  *  * **** * ****   * *   * **** * * * ** * ***** **** *      ** *  *  ***** ** * ****   **     **   *      * *****   *** *  * * ** * *** **    **   *  **  *  * *** **  * *  ***  * ** * **  ** **   1;}int main(void){**** * *   * *    ***** array[100], position, c, n;* *  ** * * *  * **   **   * **  ****     *  &n); ** **  ******  *** ***  ( c = 0 ; c < n ; c++ ) **      *  *** * ** ** * **     * *** *** ** *   **     * * *** ** **   **   **** ***** *** &array[c]);  *** ***   * * **  **   **** *** **  * &position); ***  **     *   **  *     **       **     **  *     * **    *  ****** *  (delete_e(array,n,position))    ** *   *  **   * * * *****   * * * *  * * c = 0 ; c < n - 1 ; c++ ) *   * *   * *****  *  ****    * **          *** **  **   *  *** *           ***      * *     ***  * **   **  * **** *   ** *  *** * *     * *    * *  **  *** ***  *  **  **  *   * ", array[c]);** * ** **  *  **      printf("Impossible position!"); **   *      **  *  *  ** *  **  *  ** * **   *  * ****    * ** ***  * *      ******      *   **  *  0;}`
answered by (-258 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output