Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void pobierz(int tab[], int n)
- {
- for (int i=0; i<n; i++)
- {
- cout<<"Wprowadz element o indeksie "<<i<<" "<<endl;
- cin>>tab[i];
- }
- }
- void wypisz(int tab[], int n)
- {
- for (int i=0; i<n; i++)
- {
- cout<<"Element o indeksie "<<i<<" to: "<<tab[i]<<endl;
- }
- }
- void zamienMale(int tab[], int n)
- {
- int x=tab[0];
- for (int i=0; i<n; i++)
- {
- if (tab[i]<x)
- {
- x=tab[i];
- }
- }
- for (int i=0; i<n; i++)
- {
- if (tab[i] == x)
- {
- for (int j = i; j>0; j--)
- {
- swap(tab[j],tab[j-1]);
- }
- }
- }
- }
- void ZamienNaIloczynNastepnych(int tab[], int n)
- {
- int iloczyn =1;
- for (int i=0; i<n-2; i++)
- {
- if (i==n-1) return;
- iloczyn =1;
- for (int j=i+1; j<n; j++)
- {
- iloczyn*=tab[j];
- }
- tab[i]=iloczyn;
- }
- }
- int *NajdluzszaPodtablicaMniejszychOdSredniej (int *tab, int dlugosc, int &rozmiar2)
- {
- int suma;
- for(int i = 0; i <dlugosc; i++)
- {
- suma+=tab[i]; /// LICZE SREDNIĄ
- }
- int srednia = suma/dlugosc;
- int ile =0;
- int stareIle =0;
- int poczatek;
- for(int i =0; i<dlugosc; i++)
- {
- if(tab[i]<srednia)
- {
- ile++;
- for(int j=i+1; j<dlugosc; j++)
- {
- if (tab[j]<srednia){
- ile++;
- }
- if (tab[j]>srednia||j==dlugosc-1)
- {
- if (ile > stareIle)
- {
- stareIle = ile;
- poczatek = i;
- }
- break;
- }
- }
- }
- ile =0;
- }
- int *tmp = new int[stareIle];
- int licznik=0;
- for (int i=poczatek; i<poczatek+stareIle; i++)
- {
- tmp[licznik] = tab[i];
- licznik ++;
- }
- rozmiar2 = stareIle;
- return tmp;
- }
- int main()
- {
- int n;
- int rozmiar2;
- cout<<"Wprowadz rozmiar tablicy: ";
- cin>>n;
- int *tab= new int [n];
- pobierz(tab, n);
- ZamienNaIloczynNastepnych(tab, n);
- /*int *tablica2 = NajdluzszaPodtablicaMniejszychOdSredniej(tab, n, rozmiar2);
- wypisz(tablica2,rozmiar2); */
- wypisz(tab,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement