Search code examples
numberspseudocode

Calculate the intermediate value between 3 numbers (pseudocode)


How I can find the intermediate value between 3 integers? It is possible without using external functions or many conditional?


Solution

  • for three numbers, look for the min and max. then look for the number that is neither min nor max :D

    int a=100;
    int b=200;
    int c=300;
    
    int max = (a>b)? ( (a>c)?a: (b>c)? b:c ):  ((b>c)?b: c );
    int min = (a<b)? ( (a<c)?a: (b<c)? b:c ):  ((b<c)?b: c );
    int result = (a != min && a!= max)? a: (b !=min && b !=max)? b: c;