diff --git a/algorithms/CPlusPlus/Arrays/max-min-avg.cpp b/algorithms/CPlusPlus/Arrays/max-min-avg.cpp new file mode 100644 index 00000000..55b0e093 --- /dev/null +++ b/algorithms/CPlusPlus/Arrays/max-min-avg.cpp @@ -0,0 +1,84 @@ +/* Finding maximum,minimum and average of an array + +SAMPLE INPUT: 4 + 5 + 6 + 7 + 8 + +SAMPLE OUTPUT: 8 + 5 + 6 + */ + +//Time complexity= O(n) +//Space complexity= O(n) + +//DESCRIPTION +//Problem related to find the maximum, minimum and average from the given array. + + +#include +using namespace std; + +//function to find max element in an array + +int max(int *arr, int k, int size) +{ + int i; +for(i=1; ik) + { + k=arr[i]; + } +} +return k; +} + +//function to find min element in an array + +int min(int *arr, int k, int size) +{ + int i; +for(i=1; i>size; + int *arr=new int[size]; //dynamic memory allocation + cout<<"Enter elements in an array\n"; + for (int i = 0; i < size; i++) + { + cin>>arr[i]; + } + k=arr[0]; + cout<<"Maximum element is:\n"<