#include <stdio.h>

#define MAX(a, b) (a > b) ? a : b
#define MIN(a, b) (a < b) ? a : b
#define ZERO 0
#define TEN 10
#define MAXIMUM_SHORT 32767
//---------------------------------------------------------------------------------------
//                                              Exercise 5
//                                              ----------
//
// General : The program prints the largest, smallest organ, and the sum of the series.
//           On all series..
//
// Input   : None
//
// Process : The program do sum of series and take the max mnuber and min number.
//
// Output  : Max, Min, Sum, for evert series.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date       : 23.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
    long long series = 386946543216; // example for series (start from right)
    short value,
          sum = ZERO,
          amount_values,
          amount_series;
    
    unsigned short max = ZERO;
    short min = MAXIMUM_SHORT;

    for (amount_values = series % TEN, series /= TEN; amount_values;
        series /= TEN, amount_values--, (!amount_values) ? 
        (printf("MAX: %hd\nMIN: %hd\nSUM: %hd\n", max, min, sum), amount_values = series % TEN, sum = ZERO, max = ZERO, min = MAXIMUM_SHORT, series /= TEN) : ZERO)
    {
            value = series % TEN;
            max = MAX(value, (signed short)max);
            min = MIN(value, (signed short)min);
            sum += value;
    }
}