Problem 40

3 comments on “Problem 40”


  • Oindry

    import java.util.*;
    public class PREP_P_40 {
    public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[]= new int[n];
    for(int i =0;i<n;i++)
    {
    a[i] = sc.nextInt();
    }
    int i=0;
    Arrays.sort(a);
    int sum_min=0,sum_max=0;
    for(i=0;i<n-1;i++)
    {
    sum_min=sum_min+a[i];
    }
    for(i=1;i<n;i++)
    {
    sum_max=sum_max+a[i];
    }
    System.out.print(sum_min+" "+sum_max);
    }
    }


  • sakshi

    code in CPP :
    #include
    #include
    using namespace std;
    int main()
    {
    int arr[5];
    int sum_max=0,sum_min=0;
    int max,min;
    for(int i=0; i>arr[i];
    for(int i=0; i<5; i++)
    cout<<arr[i]<<" ";
    max=INT_MIN;
    min=INT_MAX;
    for(int i=0; imax)
    max=arr[i];
    }
    for(int i=0; i<5; i++)
    {
    if(arr[i]!=max)
    sum_min=sum_min+arr[i];
    }
    cout<<"\nsum of 4 smalllest is: "<<sum_min;

    for(int i=0; i<5; i++)
    {
    if(arr[i]<min)
    min=arr[i];
    }
    for(int i=0; i<5; i++)
    {
    if(arr[i]!=min)
    sum_max=sum_max+arr[i];
    }
    cout<<"\nsum of 4 largest is: "<<sum_max;
    return 0;
    }