Please use either Java or C in Netbeans or in Xcode thank yo
Please use either Java or C++ in Netbeans or in Xcode, thank you!
1. Using Python, C Java or any other language with which you are familiar, write a well documented program that reads 10 integers, finds the sum and the average of the integers, and sorts the integers into ascending order. Specifications: a. You may use the Linux development tools on blue or any of the IDEs available in the lab. b. Your program should be stored in a single file. The name of the program should be lastnameLOla ext where lastname is your last name and .ext is the appropriate extension for the language you have chosen (py for Python, .cpp for C++, java for Java). c. Your program should prompt the user to enter 10 integer values each on a separate line d. Your program should print the integer values in their original order e. Your program should calculate and print the sum of the integer values. f. Your program should calculate and print the total of the integer values g. Your program should sort the integer values into ascending order. h. Your program should print the integer values in their sorted order. i. Sample input and corresponding output: Please enter 10 integer values Each value should be entered on a separate line 13 25 15 57 149 1489 249 88 169 The values you entered are: (13, -25, 15, 57, 149, 1489, -249, 0, 88, 169] The total of your values is 1706Solution
Here in this answer I used merge sort to sort the array.
C++ Program:
#include<iostream>
using namespace std;
void merge(int A[],int l,int m,int r)
{
int i,j,k,n1,n2;
n1=m-l+1;
n2=r-m;
int L[n1],R[n2];
for(i=0;i<n1;i++)
L[i]=A[l+i];
for(i=0;i<n2;i++)
R[i]=A[m+1+i];
i=j=0;k=l;
while(i<n1 && j<n2)
{
if(L[i]<=R[j])
{
A[k]=L[i];
i++;
}
else
{
A[k]=R[j];
j++;
}
k++;
}
while(i<n1)
{
A[k]=L[i];
i++;k++;
}
while(j<n2)
{
A[k]=R[j];
j++;k++;
}
}
void merge_sort(int A[],int l,int r)
{
if(l<r)
{ int m=l+(r-l)/2;
merge_sort(A,l,m);
merge_sort(A,m+1,r);
merge(A,l,m,r);
}
}
int main()
{
int a[10];
int sum=0;
float average;
int i;
cout<<\"Please enter 10 integer values.\"<<endl;
cout<<\"Each value should be entered on a sepearte line.\"<<endl;
for(i=0;i<10;i++)
{
cin>>a[i];
sum+=a[i];
}
cout<<\"The values you entered are :\"<<endl;
cout<<\"[\";
for(i=0;i<9;i++)
cout<<a[i]<<\", \";
cout<<a[9]<<\" \";
cout<<\"]\";
cout<<endl<<\"The total of your values is:\";
cout<<sum<<endl;
average=(sum)/(10.0);
cout<<\"The average of your values is: \";
cout<<average<<endl;
merge_sort(a,0,9);
cout<<\"The sorted values are: \"<<endl;
cout<<\"[\";
for(i=0;i<9;i++)
cout<<a[i]<<\", \";
cout<<a[9]<<\" \";
cout<<\"]\";
}

