To find maximum deviation
// maximum deviation
#include<iostream.h>
#include <math.h>
void main()
{
int a[3][3], i, j, k, max, min;
float mean, md, sum = 0;
// initializing 2 D array a with user defined values
cout<<"Enter values for array A"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"enter value for a["<<i<<"]["<<j<<"]:";
cin>>a[i][j];
}
}
cout<<endl<<endl;
// origional array A
cout<<"displaying origional array A:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
// maximum, minimum, mean and md
max = a[0][0];
min = a[0][0];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i][j] > max)
{
max = a[i][j];
}
if(a[i][j] < min)
{
min = a[i][j];
}
sum = sum + a[i][j];
}
}
cout<<"maximum value in array A is = "<<max<<endl;
cout<<"minimum value in array A is = "<<min<<endl;
mean = sum / 9;
cout<<"mean value of the array is = "<<mean<<endl;
if(abs(max - mean) > abs(min - mean))
{
md = abs(max - mean);
cout<<"maximum deviation from mean "<<mean<<" is "<<md<<endl;
}
else
{
md = abs(min - mean);
cout<<"maximum deviation from mean "<<mean<<" is "<<md<<endl;
}
cout<<endl<<endl;
}