Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

pascal source code to fin mean median modus

VIEWS: 1,137 PAGES: 3

try this.................

More Info
  • pg 1
									              Pascal soure code
       How to find mean ,median ,modus
Hi guys,,,,ow i will share a soure code how to find mean,
median ,modus in singe date....
For example :
 Data = 1,2,4,2,6
The program can answer
Ascendind date = 1,2,2,4,6
Mean :3
Median :2
Modus :2



The source code use pascal language

uses wincrt;
var i,j,f,t,t2,um,m,n,mo,ju:integer;
s,ts,r,me,ss:real;
data,fdata,ufdata:array[1..100] of integer;
begin
      clrscr;
      write('masukan jumlah data =');readln(n);
      for i:=1 to n do begin
      write('masukan data ke =',i,' = ');
      readln(data[i]);
      end;
      writeln('============================');
      write('data acak      =');
      for i:=1 to n do
       begin
        (data[i],' ');
        j:=j+data[i];
       end;
      for i:=1 to n+1 do
       begin
       for j:=i+1 to n do
        begin
         if data[i]>data[j] then
           begin
            t:=data[i];
            data[i]:=data[j];
            data[j]:=t;
           end;
        end;
       end;
      writeln;
      write('data urut      =');
      ju:=0;
      for i:=1 to n do
 begin
  write(data[i],' ');
  ju:=ju+data[i];
  r:=ju/n;
 end;
writeln;
if (n mod 2)=1 then
me:=data[(n div 2)+1] else
me:=(data[(n div 2)] + data[(n div 2)+1])/2;
write('median         =',me:10:1);
writeln;
writeln('rata-rata      =',r:5:2);
for i:=1 to n do
 begin
  for j:=1 to n do
   begin
     if data[i]=data[j] then begin
   f:=f+1;
   fdata[i]:=f;
   ufdata[i]:=f;
  end;
 end;
  f:=0;
end;
for i:=1 to n+1 do
 begin
  for j:=i+1 to n do
   begin
     if ufdata[i]>ufdata[j] then
   begin
     t2:=ufdata[i];
     ufdata[i]:=ufdata[j];
     ufdata[j]:=t2;
  end;
 end;
end;
if ufdata[n]=ufdata[(n-ufdata[n])] then um:=0 else
for i:=1 to n do
 begin
  if ufdata[n]=fdata[i] then begin
  um:=i;
 end;
end;
mo:=data[um];
if um=0 then writeln('modus         = tidak ada') else
writeln('modus nya      =',mo);
ts:=0;
for i:=1 to n do
 begin
  ss:=sqr(data[i]-r);
  ts:=ts+ss;
       end;
       s:=sqrt(ts/n);
       write('standar deviasi =',s:10:2);
end.

								
To top