Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<conio.h>
- #include<math.h>
- #include<cmath>
- #include<locale>
- #include<stdio.h>
- #include<time.h>
- #include<cstdlib>
- #include<iomanip>
- using namespace std;
- void quick_sort(int* sarr, int j)
- {
- int size= j;
- int k = 0;
- int c = sarr[(int)(j/2)];
- int tmp = 0;
- do
- {
- while(sarr[k] < c)k++;
- while(sarr[j] > c)j--;
- if(k<=j)
- {
- tmp = sarr[k];
- sarr[k] = sarr[j];
- sarr[j] = tmp;
- k++;
- j--;
- }
- } while(k <= j);
- if (j > 0) quick_sort(sarr, j);
- if (size>k) quick_sort(sarr+k,size-k);
- }
- int main()
- {
- setlocale(LC_ALL,"Russian");
- srand(time(0));
- int a[10];
- int i,s,b,sum=0,sreda=0, maxdl=0;
- cout << " Исходный массив. \n";
- for (i=0;i<10;i++)
- {
- a[i]=rand()%10;
- cout<<setw(4)<<a[i];
- }
- cout<<endl;
- quick_sort(a,10);
- int max=a[0],min=a[0];
- for( i=0;i<10;i++)
- {
- if (max<a[i]) max=a[i];
- if(min>a[i]) min=a[i];
- }
- for(i=0;i<10;i++)
- {
- sum=sum+a[i];
- }
- sreda=sum/10;
- for(i=0;i<10;i++)
- {
- if(maxdl>=a[i]-sreda)
- maxdl=a[i];
- }
- quick_sort(a,10);
- cout<<"max:"<<max<<endl;
- cout<<"min:"<<min<<endl;
- cout<<"sum:"<<sum<<endl;
- cout<<"sreda:"<<sreda<<endl;
- cout<<"maxdl:"<<maxdl<<endl;
- for( int i=0; i<10; i++)
- cout<<a[i];
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement