Biggest and smallest of four integers (No arrays, no functions, fewest 'if' statements)

后端 未结 18 2512
北海茫月
北海茫月 2020-12-10 11:29

You see, I\'ve self-taught myself C++ (not completely, I\'m still procrastinating -_-). So, now I started university and they\'re teaching C and they made us do a program of

18条回答
  •  再見小時候
    2020-12-10 12:12

     Please have at the following    
    
     private int GetLargerValue(int num1, int num2, int num3, int num4)
                {
                    int largeValue = 0;
                    if (num1 > num2)
                    {
                        if (num1 > num3)
                            largeValue = (num1 > num4) ? num1 : num4;
                        else
                            largeValue = (num3 > num4) ? num3 : num4;
    
                    }
                    else if (num2 > num3)
                        largeValue = (num2 > num4) ? num2 : num4;
                    else
                        largeValue = (num3 > num4) ? num3 : num4;
    
                    return largeValue;
                }
    

提交回复
热议问题