diff --git a/algorithms/CPlusPlus/Arrays/Largest-smallest.cpp b/algorithms/CPlusPlus/Arrays/Largest-smallest.cpp new file mode 100644 index 00000000..17b9829f --- /dev/null +++ b/algorithms/CPlusPlus/Arrays/Largest-smallest.cpp @@ -0,0 +1,20 @@ +#include +#include +using namespace std; + +//simple approach: +//sort the array in ascending order. +//the first element would be the smallest and the last element would be the largest + +int main() +{ + int arr[]={1,2,3,4,5}; + int n=sizeof(arr)/sizeof(arr[0]); + cout<a is the name of the array and n is the size of array a + cout< smallest number "< largest number "<