Find maximum of three number in C without using conditional statement and ternary operator

前端 未结 13 2001
日久生厌
日久生厌 2020-11-29 22:25

I have to find maximum of three number provided by user but with some restrictions. Its not allowed to use any conditional statement. I tried using ternary operator like bel

13条回答
  •  鱼传尺愫
    2020-11-29 22:54

    #include "stdafx.h"
    #include 
    int main()
    {       
            int x,y,z;
            scanf("%d %d %d", &x,&y, &z);
            int max = ((x+y) + abs(x-y)) /2;
            max = ((max+z) + abs(max-z)) /2;
            printf("%d ", max);
            return 0;
    }            
    

提交回复
热议问题