You are viewing a single comment's thread. Return to all comments →
Did it in C. Is there a way to make it shorter?
int main() { int *arr = malloc(sizeof(int) * 5); for(int arr_i = 0; arr_i < 5; arr_i++){ scanf("%d",&arr[arr_i]); } long sum = 0; for(int i = 0; i < 5; i++) { sum = arr[i] + sum; } long lowest = sum, new_lowest = 0, highest = 0; for(int j = 0; j < 5; j++) { long a = sum - arr[j]; if(a < lowest) { lowest = a; new_lowest = a; } if(a > highest) { highest = a; } } printf("%ld %ld", new_lowest, highest); return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Mini-Max Sum
You are viewing a single comment's thread. Return to all comments →
Did it in C. Is there a way to make it shorter?