Problem 40

10 comments on “Problem 40”


  • HEMAPRAKASH

    #include
    int main()
    {
    int a[100],n,i,j,min_sum=0,max_sum=0,temp=0;
    scanf(“%d”,&n);
    for(i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
    for(j=i+1;ja[j])
    {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
    }
    }
    }
    for(i=0;i=n-4;i–)
    {
    max_sum+=a[i];
    }
    printf(“%d %d”,min_sum,max_sum);
    }


  • Satwik

    def minmax(arr,n):
    min1=1000000
    max1=-322222
    sum1=0
    for i in arr:
    sum1+=i
    if min1>i:
    min1=i
    if max1<i:
    max1=i
    print(sum1-min1)
    print(sum1-max1)
    arr=[1,2,3,4,5]
    minmax(arr,5)


  • 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))


  • rohan

    #include
    int main()
    {
    int i,j,k,len,maxsum,minsum,sum=0,temp;
    int arr[]={1,2,35,32,32};
    len=sizeof(arr)/sizeof(arr[0]);
    for(i=0;i<len;++i)
    {
    for(j=i+1;jarr[j])
    {
    temp=arr[i];
    arr[i]=arr[j];
    arr[j]=temp;
    }
    }
    }
    for(i=0;i<len;++i)
    {
    sum+=arr[i];
    }
    maxsum=sum-arr[0];
    minsum=sum-arr[len-1];
    printf("%d %d",minsum,maxsum);
    }


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