"Z Code Writer" is an Online Blog for Programmer & Beginner. Here, You will Find tech, Build your Programming Skills and other Programming Language Like C, C++, HTML, Java Script Java Code, Web Designing and University Of Sialkot (USKT) CGPA / GPA Calculator etc.

Saturday, 25 July 2020

Find Median of Grouped And UnGrouped Data

What is Median ?

        Median is a middle value in the given sorted data. It may be ascending or descending That is called Median.

Median In Un-Grouped Data

        In Un-Grouped data we have more two categories. 
        i.     Even
        ii.    Odd

       Even

            If our observed data is even, than we need to add both center values. 
            Formula: 
Median of Ungrouped Data Formula of Even Number
Median of Ungrouped Data Formula of Even Number

        Odd

            If our Observed data is odd we simply put the middle Number on the Array. 
            Formula:
Median of Ungrouped Data Formula of Even Number
Median of Ungrouped Data Formula of Odd Number

Median In Group Data 

        In this method we have given class intervals and frequency we simply solve this using formula.
        Formula:
Formula of Median in grouped Data
Formula of Median in grouped Data

Median of Un-Group Data Code / Program in C /C++

#include<iostream>
using namespace std;
int main(){
int num;
float x[10],sum=0,mean,temp[10],Oloc,Eloc;
cout<<"Enter Total Number ";
cin>>num;
cout<<"X"<<endl;
for(int i=0;i<num;i++){
cin>>x[i];
}
cout<<" Given Data is: ";
for(int i=0;i<num;i++){
cout<<x[i]<<", ";
}
for(int i=0;i<num;i++){
for(int j=i+1;j<num;j++){
if(x[i]>x[j]){
temp[i]=x[i];
x[i]=x[j];
x[j]=temp[i];
}
}
}
cout<<endl<<" Arange : ";
for(int i=0;i<num;i++){
cout<<x[i]<<", ";
}
cout<<endl;
if(num % 2 == 1){
Oloc=x[num/2];
cout<<" Median of Odd Data is "<<Oloc;
}
else{
Eloc=(x[num/2-1]+x[num/2])/2;
cout<<" Median of Even Data is "<<Eloc;
}
return 0;
}

Input

Odd Data
Enter Total Number 9
X
5
7
9
8
3
2
1
6
4
 Given Data is: 5, 7, 9, 8, 3, 2, 1, 6, 4,
 Arange : 1, 2, 3, 4, 5, 6, 7, 8, 9,
 Median of Odd Data is 5

Output


Input

Even Data

Enter Total Number 8
X
5
1
2
9
7
3
2
4
 Given Data is: 5, 1, 2, 9, 7, 3, 2, 4,
 Arange : 1, 2, 2, 3, 4, 5, 7, 9,
 Median of Even Data is 3.5

Output

Median of Group Data Code / Program in C /C++

#include<iostream>
using namespace std;
int main(){
float num,sumf=0,median=0,sumCF=0;
float start[10],end[10],f[10];
cout<<" \t\t <<----- Median Of Grouped Data ----->> "<<endl<<endl<<endl;
cout<<"Enter Total Number ";
cin>>num;
cout<<"Enter Class Intrvals"<<endl;
for(int i=0;i<num;i++){
cout<<i+1<<"- Range Start ";
cin>>start[i];
cout<<i+1<<"- Range End ";
cin>>end[i];
}
for(int i=0;i<num;i++){
cout<<i+1<<"- Enter Frequency of this Range ";
cin>>f[i];
}
int CF[10],loc,index;
float CBStart[10],CBEnd[10];
for(int i=0;i<num;i++){
sumf=sumf+f[i];
CF[i]=sumf;
CBStart[i]=start[i]-0.5;
CBEnd[i]=end[i]+0.5;
loc=sumf/2;
}
for(int i=0;i<num;i++){
if(CF[i]>=loc){
index=i;
i=num;
}
}
cout<<endl;
cout<<"Class Interval Frequency Class Boundaries Cumulative Frequency"<<endl;
for(int i=0;i<num;i++){
cout<<start[i]<<" - "<<end[i]<<"\t\t"<<f[i]<<"\t\t"<<CBStart[i]<<" - "<<CBEnd[i]<<"\t\t\t"<<CF[i]<<endl;
}

float l,h,f1,c;
l=CBStart[index];
h=(end[index]-start[index])+1;
f1=f[index];
c=CF[index-1];
cout<<endl;
cout<<" Lower Class Boundary (l) "<<l<<endl;
cout<<" Hight (h) "<<h<<endl;
cout<<" Frequency oF Location (f) "<<f1<<endl;
cout<<" Sum of Frequency (Sum(f) "<<sumf<<endl;
cout<<" C (C) "<<c<<endl;
cout<<endl;
median=(l+(h/f1)*((sumf/2)-c));
cout<<"Median = l+(f/n)*((sum(F)/2)-c) = "<<median;
return 0;
}

Input

Enter Total Number 5
Enter Class Intrvals
1- Range Start 2
1- Range End 4
2- Range Start 5
2- Range End 7
3- Range Start 8
3- Range End 10
4- Range Start 11
4- Range End 13
5- Range Start 14
5- Range End 16
1- Enter Frequency of this Range 6
2- Enter Frequency of this Range 3
3- Enter Frequency of this Range 9
4- Enter Frequency of this Range 10
5- Enter Frequency of this Range 12

Output



No comments:

Post a Comment

Thanks For Visiting Here...!! I will Reply you as soon as possible.