From f56e89d529eb403783427d9387c70b3d6629375c Mon Sep 17 00:00:00 2001 From: viveksoni2911 <72186174+viveksoni2911@users.noreply.github.com> Date: Thu, 20 Oct 2022 11:34:50 +0530 Subject: [PATCH] Create 011_Span_Of_Array 1. You are given a number n, representing the count of elements. 2. You are given n numbers. 3. You are required to find the span of input. Span is defined as difference of maximum value and minimum value. Input Format A number n n1 n2 .. n number of elements Output Format A number representing max - min --- 002_ARRAY/011_Span_Of_Array | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 002_ARRAY/011_Span_Of_Array diff --git a/002_ARRAY/011_Span_Of_Array b/002_ARRAY/011_Span_Of_Array new file mode 100644 index 0000000..9d6f561 --- /dev/null +++ b/002_ARRAY/011_Span_Of_Array @@ -0,0 +1,29 @@ +#include +using namespace std; + +int main(){ + //write your code here + + int n; + cin>>n; + int* arr = new int[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + + int min = arr[0]; + int max = arr[0]; + + for(int i = 1; i < n; i++){ + if(arr[i] > max){ + max = arr[i]; + } + + if(arr[i] < min){ + min = arr[i]; + } + } + + int ans = max - min; + cout<