Sort by

recency

|

1962 Discussions

|

  • + 0 comments

    HERE'S A BASIC AND UNDERSTANDABLE APPROACH

    include

    include

    include

    using namespace std;

    int max_of_four(int a, int b, int c, int d) { vector v1 = {a, b, c, d}; // Initialize vector int maxi = v1[0]; // Start with the first element

    for (auto i = v1.begin(); i != v1.end(); i++) {
        if (*i > maxi) { // Compare correctly
            maxi = *i;
        }
    }
    
    return maxi;
    

    }

    int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); int ans = max_of_four(a, b, c, d); printf("%d", ans);

    return 0;
    

    }

  • + 0 comments

    include

    using namespace std;

    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; } /* Add int max_of_four(int a, int b, int c, int d) here. */

    int main() { int a=3, b=4, c=6, d=5; cin>>a>>b>>c>>d;

    cout<<max_of_four(a,b,c,d)<<endl;
    return 0;
    

    }

  • + 0 comments

    Bros this code is also return the max value but they are not accepting this code int max_of_four(int a,int b,int c,int d){ if(a>b&&a>c&&a>d){ return a; } else if(b>a&&b>c&&b>d){ return b; } else if(c>a&&c>b&&c>d){ return c; } else{ return d; } }i

  • + 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;
    }`