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

前端 未结 15 2153
遇见更好的自我
遇见更好的自我 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 08:04

    This is not an efficient answer but it still works

    int a,b,c,d,e,largest;
    if ((a>b) and (a>c) and (a>d) and (a>e))
    {    
        largest=a;
    }
    else if ((b>a) and (b>c) and (b>d) and (b>e))
    {    
        largest=b;
    }
    else if ((c>a) and (c>a) and (c>d) and (c>e))
    {    
        largest=c;
    }
    else if ((d>a) and (d>c) and (d>a) and (d>e))
    {    
        largest=d;
    }
    else 
    {
    largest=e;
    }
    

    you can use similar logic to fid the smallest value

提交回复
热议问题