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
#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);
}
Comments
Leave a comment