I wrote the following code-
#include <iostream>
#include <tuple>
int sumarr(int64_t arr[], int length)
{
long long int sum= 0;
for(int i=0; i<length; i++)
{
sum += arr[i];
}
return sum;
}
void minimaxval(int64_t arr[], int length,int64_t *x,int64_t *y)
{
long long int c=0;
long long int d=10e9;
for(int j=0; j<5; j++)
{
if(arr[j] >= c)
{
c = arr[j];
}
if (arr[j] <= d)
{
d= arr[j];
}
}
*x=c;
*y=d;
}
int main()
{
int64_t arr[5];
int64_t p, q;
int64_t sum;
for(int k=0; k<5; k++){
std::cin>> arr[k];
if (arr[k]<1 || arr[k]>10e9){return 0;}
}
sum= sumarr(arr, 5);
minimaxval (arr, 5, &p, &q);
std::cout << sum-p << " " << (sum-q);
return 0;
}
This is my first question on stackoverflow. So I dont know a lot about format.
Input for the que. will be 5 space-separated integers. Output should be the minimum sum and the maximum sum we can get by removing only one integer from the list.
It does not show any compiler issues.
It works fine for smaller integers but outputs a negative value for larger integers.
Where did I go wrong.