From af47764be0a200649d74650d4cdfe34d46d8b3f8 Mon Sep 17 00:00:00 2001 From: Uma-95 <99042417+Uma-95@users.noreply.github.com> Date: Thu, 22 Dec 2022 18:59:25 +0530 Subject: [PATCH] chore(CPlusPlus): add largest and smallest number in an array (#1110) --- .../CPlusPlus/Arrays/Largest-smallest.cpp | 20 +++++++++++++++++++ algorithms/CPlusPlus/README.md | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 algorithms/CPlusPlus/Arrays/Largest-smallest.cpp 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 "<