#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
float suma(float tab[], int n){
int i;
float s=0;
for(i=0;i<n;i++)
s=s+tab[i];
return s;
}
float iloczyn(float tab[], int n){
int i;
float a=1;
for(i=0;i<n;i++)
a=a*tab[i];
return a;
}
void liniowe(float tab[], int n){
int i;
for(i=1; i<n; i++){
int j=i;
int tem=tab[j];
while((j>0) && (tab[j-1]>tem)){
tab[j]=tab[j-1];
j--;
}
tab[j]=tem;
}
}
void mediana(float tab[], int n){
if(n%2!=0)
cout<<"Mediana: "<<tab[(n-1)/2]<<endl;
else
cout<<"Mediana: "<<(0.5*(tab[(n-2)/2]+tab[n/2]))<<endl;
}
void arytmetyczna(float suma, int n){
cout<<"Srednia arytmetyczna: "<<suma/n<<endl;
}
void geo(float a,int n){
cout<<"Srednia geometryczna: "<<powf(a,(1.0/n))<<endl;
}
int main(){
ifstream we("lab10p3.txt"),we2;
string liczby1;
int ileliczb=0;
while(!we.eof()){
we >> liczby1;
ileliczb++;
}
float liczby[ileliczb]={0};
we2.open("lab10p3.txt");
if(we2.is_open()){
string a;
for(int i=0;i<ileliczb;i++){
we2 >> a;
liczby[i]=atoi(a.c_str());
}
liniowe(liczby, ileliczb);
cout<<"Suma: "<<suma(liczby,ileliczb)<<endl;
cout<<"Iloczyn: "<<iloczyn(liczby,ileliczb)<<endl;
arytmetyczna(suma(liczby,ileliczb),ileliczb);
geo(iloczyn(liczby,ileliczb),ileliczb);
mediana(liczby,ileliczb);
}
we2.close();
we.close();
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}