Problem 40

7 comments on “Problem 40”


  • shushank

    #Python Progamming

    l=list(map(int,input().split(” “)))
    l.sort()
    l1=[]
    l2=[]
    l1[:]=l[0:len(l)-1]
    l2[:]=l[1:]
    print(sum(l2),sum(l1))


  • TADEPALLI

    #include
    #include
    int main()
    {
    int arr[5],i;
    int sum_max=0,sum_min=0;
    int max,min;
    for(i=0;i<5;i++)
    scanf("%d",&arr[i]);
    max=INT_MIN;
    min=INT_MAX;
    for(i=0;imax)
    max=arr[i];
    }
    for(i=0;i<5;i++)
    {
    if(arr[i]!=max)
    sum_min=sum_min+arr[i];
    }
    for(i=0;i<5;i++)
    {
    if(arr[i]<min)
    min=arr[i];
    }
    for(i=0;i<5;i++)
    {
    if(arr[i]!=min)
    sum_max=sum_max+arr[i];
    }
    printf("Sum of 4 smallest element is: %d\n",sum_min);
    printf("Sum of 4 largest element is: %d\n",sum_max);
    return 0;
    }


  • Chandra Chandu

    cpp

    #include
    using namespace std;
    int main()
    {
    long int i,j,n,t,sum=0;
    cin>>n;
    int a[n];
    for(i=0;i>a[i];
    sum=sum+a[i];
    }
    int p=*min_element(a,a+n);
    int v=*max_element(a,a+n);
    cout<<sum-v<<" "<<sum-p<<endl;;
    return 0;
    }


  • 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;
    }