C++ Program Code for Mean and Median of Numbers

Program Code:

#include<iostream>
using namespace std;
int main()
{
int num ,count = 0;
double arr[10],out[10] ;
double median ,mean , sum = 0;
cout<<"Enter 10 integers:  \n";
for(int i=0;i<10;i++)
{
cout<<"\t";
cin>>arr[i];
cout<<"\n";
}
cout<<"Integers are : "<<"[";
for(int j=0;j<10;j++)
{
cout<<" "<<arr[j]<<" ";
}
cout<<"]";
//ascending order
for(int k=0;k<10;k++)
{
for(int l=0;l<10;l++)
{
if(arr[l]>arr[l+1])
   {
    num = arr[l];
arr[l]=arr[l+1];
arr[l+1]=num;
   }
}
}
cout<<"\nAscending order : [";
for(int m =0 ; m<10 ; m++)
{
cout<<" "<< arr[m] <<" ";
}
cout<<"]";
// mean
cout<<"\nMean :  ";
for(int n=0;n<10;n++)
{
sum += arr[n]; 
}
mean = sum / 10;
cout<<mean;
    
    //median
cout<<"\nMedian :  ";
median = (arr[4] + arr[5]) / 2;
cout<<median;
return 0;
}

Output:

.exe file

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.