0 like 0 dislike
3.6k 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.

寫一個delete_e(int arr[], int size, int position) 刪除一個陣列元素的函數。刪除後陣列大小不變。

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

如果刪除可行的話 return 1,不可行return 0 (陣列大小五 刪除第六個元素)

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 in Chapter 9: Functions by (5.2k points)
ID: 35785 - Available when: 2017-12-07 18:00 - Due to: Unlimited

edited by | 3.6k views

47 Answers

0 like 0 dislike
Hidden content!
#include ** * ** *
int * arr[],int size,int position)
{
* * * * * ***** ** ***** YOUR CODE HERE*/
* ** * * ** *** * ** a;
* ********* **** ** * * *** ** * * *
** * * * ** * *** * 0;
* * * *** ** * ** ** ** * * **
** ** **** * * *
* ** ** * * * ** * *** * *** **** **

******** * *
* * ** **** ** * *** * * * * 1;


* * ***** *** ** *
* *** ** * * * OF YOUR CODE*/
}

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 (-204 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;
** *** * ***** * *** * ** * ******
* * * ** *
* * ** ** * * * *** ** *** **** * = arr[i+1];
***** **** * * **
* **** ***** * * * *** **** || * * * * ******
* * **** ** **** ****
*** ** ****** * ***** * ** * ** * 0;
* ** * ** * * ***
* ** * * *
*** * * * * **** * * 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 (-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)
{

* * ** ***** ** * YOUR CODE HERE*/
int i;
* ** *** * * *** ** * ** * **** ** *** * ** ***** ***** * * * ** ** *** **
* ** ** *** * ** * *** *** ** * ** * * * ** **** **
*** * * * ** ** ** * ** * *** **** **** *** ** *** *** * * * * * i++)
* * * * * * ******** * * * ** *** * **
* * * ** * ******* **** *** * * ** ** ** * * * ** ** * * * = arr[i + 1];
* ** ***** *** * * * * ** *** **** * ** return 1;
* **** ** * * ** * ** * ** ** * *

** * *** ** * **** * return 0;


* * ** * *** * * 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 (-304 points)
edited by
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
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)
{
* * * *** *** *** ** * i;
* * *** ***** * * ** ** **
* *** **** ** ** *** * **** ** * * **
**** * ** ** * **
** *** * * ** *** * *** * ** ** *** * * *** ** ****
**** * *** * * * * * ***** * * * * ** **
* *** ** ** *** * * * * * * * *
** *** ** ************ ** * * * * *** * ****** * *** ****** * **** *
** ** *** *** * *** ** ****** ** * * * *
*** * * *****
* * * * *** * ** ** * **
* ** * ** **
****** * *** ** *** ** ** ** **** *** * * 0;
** *** ***
}

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

** * * *** * *** * ****** *** &n); //Enter number of elements in array
* ****** * ( c = 0 ; c < n ; 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
* ** ** ******* * **** * * * *** ** * * ** ** ** * *** ** * * * *** ** ", array[c]);
* * **** ** * ** ** * * ** ** * ** * position!"); * * ** ** *** ** * * *** ** * * * ** * ** ** ** *** * ** ** * * ***** *** *** fail

** ** * * * * * ** ** 0;
}
answered by (-108 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)
{
* ** * a=0,i;
* *** * * *** * * * ** * *** *** *****
*** * *** * * * ** *
** * *** * ******* *** * **** *** * ** * **
* ***** * ***** * * * *
** * * ** ** *** *** * *** * *** * *
** ** ** * * * ** **** *
* **** * *** *** * ************* ** ** ** **** * 0;
* **** * * * * * * **
}

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 (-329 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)
{
* * * * ** * i;
* * * ** ** * * * ***** * ***
*** * **** ** ** ** **
* * ** * ** * **** * * * * ** * **
**** ********** ** *
* ***** * ** ** ** *** * **
*** ** *** * *
*** * * ** ** ** * *** *** ** *** * ** 0;
* * * * * ** ** * *
** ******* ** *** *
* ** * * *** * * * * * 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 (-229 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)
{
*** * * * ** a=0,i;
* *** ** **** * * * *** **** **** * * **
**** *** * *** * * *
* * **** ** ** ***** * * ***** * *** * * * * ***
* * * * ******** *** ** **
}

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 (-329 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 <stdio.h>
int delete_e(int arr[],int size,int position)
{
* * ** * *** **** * * YOUR CODE HERE*/
if * * * * * * ***** *
* ** * * * ** * **** * ** * * 0;
}else
{
** ** * * ****** **** * i,a,b,c;
** * * * *** ***** times=size-position;
* ***** *** ** *** * * ****
   {
** * * *** *** **** * ** *** * *** *
********** * * *** ** ** * * ** * * ** *
***** *** *** * * ** * * * * * ** ***

* *** ** * * * * *** **** *** *
   }

 return 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
** * * ** ** *** ** * **** ** **** * * * * * *** ******* * &array[c]);



* * * * * * *** ***** * ** ** * ** *** * * *** * * **** * * ** * *** * * * * * *** * ****** * * * * * * ** ***** * *** ** *** ** ** ** * ** * *** ** ** ***** * ** * ** **** * **** *** ** * * ** ** *** ** ** ** * * * * *** *** * * * * ** * ** ** ****** * **** * * ***** ** *** **** ** * ***** * ** * *** * ** *** * ** ** ***** * *** * * ** *** * * **** ** ** ** * ** **** ****** * * * * ** ** *** * &position); *** **** **** ********* * ** * * **** ** the location where you wish to delete element

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

** * **** * 0;
}
answered by (-336 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;
***** ***** * * * *** * * || position **** *
* ** ** * * ** **** 0;
** * * ** **** *** *
** ** * * ** * * ** * *** * ** ****
* *** * ** * * **** * * *
* * ** * **** *** *** ****
}

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 (-281 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;
** * * * * *** * ** * * ** *** || position * ** *
* * * * ** ** *** * ** 0;
* ***** **** * *
******** **** ** ***** * * * **
** * ** * * * * **** * * ***
}

int **
{
* * *** * *** ** * * ** ** ** 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 (-281 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.254.132
©2016-2024

Related questions

0 like 0 dislike
45 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 35784 - Available when: 2017-12-07 18:00 - Due to: Unlimited
| 3.8k views
0 like 0 dislike
79 answers
[Exercise] Coding (C) - asked Dec 28, 2017 in Chapter 9: Functions
ID: 39986 - Available when: Unlimited - Due to: Unlimited
| 7.4k views
0 like 0 dislike
70 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 35783 - Available when: 2017-12-07 18:00 - Due to: Unlimited
| 5.1k views
12,783 questions
183,443 answers
172,219 comments
4,824 users