Question

pls help Write a method void remove(int *a, int index) that will remove the number at...

pls help

Write a method void remove(int *a, int index) that will remove the number at the
given index and shift all remaining numbers one position to the left in the array a. Assume
1that the last element of the array is -1. Now, write a main function that will define an array
int A[40]=[3, 5, 9, 17, 24, -1]; read from user input an index; and call the method
remove passing array A and the index given by the user. For example if user enters 2, then
number 9 at index 2 will be removed and the array will now contain [3, 5, 17, 24, -1]
Print the array after the removal. You MUST write the remove method using ONLY pointers
and pointer arithmetic (no array notation [ ] allowed).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code in c

#include<stdio.h>

void remove1(int *, int );

void main()

{

int A[40]={3,5,9,17,24,-1};

int index;

printf("Please enter the valid index :");

scanf("%d",&index);

remove1(A,index);

}

void remove1(int *a, int index)//remoe1 function

{

int i,n=0;//variables n used for finding the length of the array

for(i=0;a[i]!='\0';i++)

n++;

for (i = index; i < n - 1; i++)//then from the next element from the indexed element

{

a[i] = a[i + 1];

}

//prints the resultant array.

printf("The resultant array is is \n");

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

{

printf("%d\n", a[i]);

}

}

output

Sums of array element - Microsoft Visual Studio Quick Launch (Ctrl+Q) ELE EDIT YIEW PROJECT BUILD DEBUG TEAM SQL İOOLS TEST ARCHITECTURE ANALYZE WNDOw HELP o 迟, ぐ Local Windows Debugger, Debug crtexe.ca ×▼ solution Explorer (Global Scope) include< φ remove 1 (int . a, int index) , Search Solution Explorer (Ctrl+, -solution . Sums of array element ▲ [ Sums of array element void void main Please enter the valid index 2 The resultant array is is int A int i print scanf Header Files -Resource Files Source Files 24 ress any key to continue .. . Source1.c E void reno int i for(i Output Show output from 1)--Buil 1 Sourcei.c sing scanf_s instead. To disable 1> 1 Sums of a Error List Output Build succeeded ENG 15:49 -IN 17-10-2018 ^if you have any query regarding the code please ask me in the comment i am here for the help. Please do thumbs up for me. Thank You.If you require in another language please ask me in the comment .

Add a comment
Know the answer?
Add Answer to:
pls help Write a method void remove(int *a, int index) that will remove the number at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • You are to write three functions for this lab: mean, remove, display. Download the main.cpp file...

    You are to write three functions for this lab: mean, remove, display. Download the main.cpp file provided to get started. Read the comments in the main function to determine exactly what the main function should do. //include any standard libraries needed // - Passes in an array along with the size of the array. // - Returns the mean of all values stored in the array. double mean(const double array[], int arraySize); // - Passes in an array, the size...

  • public boolean remove (int num) removes the first occurrence of the number num from the bag...

    public boolean remove (int num) removes the first occurrence of the number num from the bag Implement remove(int num) method that removes the first occurrence of the number num in the list array. If the number num does not exist then the method does not do anything. If removal is successful and the number removed is not the last number in the list, then shift the elements by one place to the left in the list (i.e. fill in the...

  • Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr,...

    Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr, int count, int key ) { 1: find the index of the first occurance of key. By first occurance we mean lowest index that contains this value. hint: copy the indexOf() method from Lab#3 into the bottom of this project file and call it from inside this remove method. The you will have the index of the value to remove from the array 2:...

  • Code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; ...

    code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; Specification: In this lab, five functions need to be implemented using the given ADT. 1. Employee* readRecord(FILE*) This function receives a FILE pointer created before. It reads a line from the provided csv file, and creates an Employee struct pointer with the information from that line then returns the pointer back to the calling function. Each line in the provided csv file contains the id, salary,...

  • Write a c program that finds the uncommon elements from two array elements using pointers only...

    Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...

  • Write a C program that prompts the user to enter a series of integers that represent...

    Write a C program that prompts the user to enter a series of integers that represent a coded message. I have given you the decoder program so that you can see how it is written using array notation. Your assignment is to convert the code to a program that uses only pointers and pointer math. Your program must use pointer notation and pointer math (i.e. no array index notation other than in the declaration section, no arrays of pointers and...

  • Need help to answer this method in java Write a method int indexFirstOne(int[ ] input) The...

    Need help to answer this method in java Write a method int indexFirstOne(int[ ] input) The input array is sorted, and every element is 0 or 1. Return the index of the first 1. If there are no 1s in the array, return -1. The worst-case runtime must be O(logn)where n is the number of elements (no credits for slower runtimes) Example: a = [0,0,1,1,1]      return 2 a = [ 0,0,0,1]          return 3 a = [0,0,0]              return -1 int indexFirstOne...

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Use JAVA language. public class DynamicArray2 { private String[] data; // the backing array private int...

    Use JAVA language. public class DynamicArray2 { private String[] data; // the backing array private int virtualArrayLength; // the number of elements in the dynamic array // Throws an IndexOutOfBoundsException if i is not a valid index // for adding to the dynamic array, otherwise inserts s at index i. // Elements can be added from index 0 to this.size(). public void add(int i, String s) { // If there is no room for s in data, create a new...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT