Witam, w żaden sposób nie potrafię dodać do mojego programu Mediany i Dominanty, które liczone będą z posortowanej tablicy.
Czy ktoś potrafi mi pomóc?
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int t[21];
void generuj(int n)
{
for(int i = 0; i < n; i++) t[i]=rand()%100;
cout << "\nTablica zostala wygenerowana, oto elementy: " << endl;
for(int i = 0; i < n; i++) cout << " | " << t[i];
}
int main(void)
{
start:
cout<<endl;
srand(time(0));
int n,temp;
int k,l,p,z;
cout << "Podaj rozmiar tablicy(max. 21): ";
cin >> n;
cout<< "- - - MENU - - -" <<endl;
cout<< "1. Liczby losowe" <<endl;
cout<< "2. Wprowadzam sam" <<endl;
cout<< "3. Stala tablica" <<endl;
int liczba;
cout << endl << "Metoda wprowadzania: ";
cin >> liczba;
cout<<endl;
system( "cls" );
switch( liczba )
{
case 2:
cout << "Wprowadz liczby: " << endl;
for (int i=0;i<n; i++) cin>> t[i];
cout<<endl;
cout<< "Tablica nie posortowana: "<< endl;
for (int i=0; i<n; i++) cout<<" | " << t[i] ;
break;
case 1:
generuj(n);
break;
case 3:
cout << "Stala tablica: " << endl;
t[0]=7;
t[1]=5;
t[2]=2;
t[3]=1;
t[4]=3;
t[5]=9;
t[6]=11;
t[7]=16;
t[8]=20;
t[9]=2;
t[10]=4;
t[11]=5;
t[12]=18;
t[13]=12;
t[14]=13;
t[15]=7;
t[16]=17;
t[17]=19;
t[18]=0;
t[19]=1;
t[20]=2;
for (int i=0; i<n; i++) cout<<" | " << t[i] ;
break;
}
cout<<endl;
// MIN,MAX,ŚREDNIA
float suma=0;
int max=t[0],min=t[0],pozmin=0,pozmax=0;
for(int i=0;i<n;i++) {
if(max<t[i]){ max=t[i];
pozmax=i;
}
if(min>t[i]) {
min=t[i];
pozmin=i; }
suma+=t[i];
}
cout<<endl<<"MIN: "<<min<<" > INDEKS "<<pozmin<<endl;
cout<<endl<<"MAX: "<<max<<" > INDEKS "<<pozmax<<endl<<endl;
cout<<"AVG: "<<suma/n;
//SORTOWANIE
for(int j=n-1;j>0;j--)
{
for(int i = 0; i<j;i++)
{
if(t[i]>t[i+1])
{
int temp=t[i];
t[i]=t[i+1];
t[i+1]=temp;
}
}
}
cout << "\n\nPosortowane elementy:"<<endl;
for(int i=0;i<n;i++) cout << " | " << t[i];
cout<<endl;
cout<<endl<<endl<<endl;
cout<< "Powtorzyc program?"<<endl;
cout<< "1. Tak"<<endl;
cout<< "2. Nie"<<endl;
int daw;
cout << endl << "Wybor: ";
cin >> daw;
cout<<endl;
switch( daw )
{
case 1:
system( "cls" );
goto start;
break;
}
cout<<endl;
return 0;
}