You are viewing a single comment's thread. Return to all comments →
HERE'S A BASIC AND UNDERSTANDABLE APPROACH
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;
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Functions
You are viewing a single comment's thread. Return to all 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
}
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);
}