franvergara66
franvergara66

Reputation: 10784

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?

Upvotes: 0

Views: 748

Answers (1)

Angel Koh
Angel Koh

Reputation: 13525

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;

Upvotes: 1

Related Questions