Mini-Max Sum

  • + 0 comments

    in C

    void miniMaxSum(int arr_count, int* arr){
        
        /* long int because the output more than 32 bit so we will deal with (long int) 64 bit*/
        
        long int maxN=arr[0],     /* max number in array*/
         minN=arr[0],             /* min number in array*/
          sum=0;                  /* the sum of all elements */
        
        for(int i=0;i<arr_count;i++){
            if(maxN < arr[i]) maxN = arr[i]; /* max number in array */
            if(minN > arr[i]) minN = arr[i]; /* min number in array */
            sum+=arr[i];                     /* summing */
        }
     
         /* the lowest value is sum-maxValue, the highest value is sum-minValue*/   
        printf("%ld %ld\n",sum-maxN, sum-minN);
    }