Program to find largest and smallest among 5 numbers without using array

前端 未结 15 2224
遇见更好的自我
遇见更好的自我 2021-01-06 07:25

Yesterday I went for an interview where I have been asked to create a program to find largest and smallest among 5 numbers without using array.

I know how to create

15条回答
  •  独厮守ぢ
    2021-01-06 07:54

    The > and < are transitive properties, so if a > b and b > c, then a > c. So you can

    int a=10, b=6, c=4, d=21, e=4;
    
    int maxNum = a;
    int maxNum = max(b, maxNum);
    int maxNum = max(c, maxNum);
    int maxNum = max(d, maxNum);
    int maxNum = max(e, maxNum);
    

提交回复
热议问题