Sort by

recency

|

1959 Discussions

|

  • + 0 comments
    int max_of_four(int a, int b, int c, int d) {
        int max = a > b ? a : b;
        max = c > max ? c : max;``
        return d > max ? d : max;
    }
    
  • + 0 comments
    int max_of_four(int a, int b, int c, int d){
        int max = a > b ? a : b;
        if(c > max) max = c;
        return d > max ? d : max;
    }`
    
  • + 0 comments

    can you do better ??

    int max_of_four(int a,int b,int c,int d)
        {    
            int max = a;
            
            if(b>max){max = b;}
            if(c>max){max = c;}
            if(d>max){max = d;}
            
            return max;
        }
    
  • + 0 comments
    {
        int numList[4] = {a, b, c, d};
        int result = 0;
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (numList[i] > numList[j] && numList[i] > result)
                {
                    result = numList[i];
                }
                else 
                {
                    continue;
                }
            }
        }
        return result;
    }
    
  • + 1 comment

    Here are my simple code:

    int max_of_four(int a, int b, int c, int d)
    {
    
        int aux = 0;
    
        int arr[4] = {a, b, c, d};
    
        for (int i = 0; i <= 4; i++)
        {
            if (arr[i] > aux)
            {
                aux = arr[i];
            }
        }
    
        return aux;
    }