Answer to Question #276469 in C for Shweta

Question #276469

Write a program which should consists of a user defined function “Task ()” [Function returns no 

value]. Pass 1D array to the function, along with number of elements of array. Function should delete 

the largest element from the passed array. Display the final array after deletion [After function is called] 

in the main () function


1
Expert's answer
2021-12-07T09:21:46-0500
#include<iostream>
using namespace std;
void Task (int arr[], int size){
	int max = arr[0];
	int k = 1;
	for(int i=0; i<size; i++){
		if(arr[i]>max){
			max = arr[i];
			k = i;
		}
	}
	k  = k + 1;
	for(int i=k-1; i<size-1; i++)
        {
            arr[i] = arr[i + 1];
        }


       
        size--;


       
        printf("\nFinal elements of the array after delete are : ");
        for(int i=0; i<size; i++)
        {
            printf("%d\t", arr[i]);
        }
}
int main(){
	int arr[5] = {10, 20, 30, 40, 50};
Task(arr,5);
	 
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS