4 of 5
edited title
Bruno Costa
  • 5.6k
  • 19
  • 42

Get Minimum of four and maximum up to a limit

Input and Output Format: Input consists of 5 integers that correspond to r1, r2, r3, r4 and x. Output consists of 2 integers. The 1st integer corresponds to the minimal amount she would spend for buying 3 gifts. The 2nd integer corresponds to the maximal amount she would spend for buying 3 gifts.

Sample Input :

20 30 10 25 80

Sample Output :

55 75

  #include<stdio.h>

 int main()
 {
int x,a[4],i,j,n,temp,big,small,sum=0;

// scanf("%d",&r1);
// scanf("%d",&r2);
// scanf("%d",&r3);
// scanf("%d",&r4);
// scanf("%d",&x);
big = 0;
n=4;
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
}
scanf("%d",&x);
for(i=0;i<n;i++)
{
    for(j=i;j<(n);j++)
    {
        if(a[i]>a[j]){
            temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
    }
    sum+=a[i];
}
//sum = a[0]+a[]
small = sum-a[3];

if((sum-a[0])<=x)
big = sum-a[0];
else if((sum-a[1])<=x)
big = sum-a[1];
else if((sum-a[2])<=x)
big = sum-a[2];
else
big = small;


if(small<=x){
    printf("%d",small);
}

if(big == small){
    return 0;
}

if(big<=x){
    printf("\n%d",big);
}
return 0;
}