Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //ââîä è âûâîä
- #include <string.h> //ñòðèíãîâûé òèï
- #include <windows.h> //system äëÿ íåêîòîðûõ êîìïèëÿòîðîâ
- #include <time.h>
- #include <algorithm>
- using namespace std;
- void start();
- void genMass(int*, int);
- void printMass(int*, int);
- void maxMass(int*, int, int);
- void sortMass(int*, int);
- int main(){
- setlocale(LC_ALL,"RUSSIAN");
- start();
- system("pause");
- return 0;
- }
- void start(){
- int n;
- srand(time(NULL));
- n = 1+rand()%10;
- int *arr1 = new int[n];
- genMass( arr1, n);
- printMass( arr1, n);
- int n1 = n;
- n = 1+rand()%10;
- int *arr2 = new int[n];
- genMass( arr2, n);
- printMass( arr2, n);
- int n2 = n;
- n = 1+rand()%10;
- int *arr3 = new int[n];
- genMass( arr3, n);
- printMass( arr3, n);
- int n3 = n;
- n = 1+rand()%10;
- int *arr4 = new int[n];
- genMass( arr4, n);
- printMass( arr4, n);
- int n4 = n;
- n = 1+rand()%10;
- int *arr5 = new int[n];
- genMass( arr5, n);
- printMass( arr5, n);
- int n5 = n;
- cout << endl;
- maxMass (arr1, n1, 1);
- maxMass (arr2, n2, 2);
- maxMass (arr3, n3, 3);
- maxMass (arr4, n4, 4);
- maxMass (arr5, n5, 5);
- cout << endl;
- sortMass (arr1, n1);
- printMass (arr1, n1);
- sortMass (arr2, n2);
- printMass (arr2, n2);
- sortMass (arr3, n3);
- printMass (arr3, n3);
- sortMass (arr4, n4);
- printMass (arr4, n4);
- sortMass (arr5, n5);
- printMass (arr5, n5);
- }
- void genMass(int *arr, int n){
- int num;
- for ( int i = 0; i<n; i++ ){
- num = 1+rand()%100;
- arr[i] = num;
- }
- }
- void printMass(int *arr, int n) {
- for ( int i = 0; i<n; i++ )
- cout << arr[i] << " ";
- cout << endl;
- }
- void maxMass(int *arr, int n, int p){
- int max = 0;
- for (int i = 0; i<n; i++){
- if ( arr[i] > max )
- max = arr[i];
- }
- cout << "Ìàêñèìàëüíîå ÷èñëî " << p << "-ãî ìàññèâà ðàâíî " << max << endl;
- }
- void sortMass (int *arr, int n){
- int change = 0;
- for (int d = 0; d < n; d++){
- for ( int i = 0; i<n-1; i++ ){
- if ( arr[i] > arr[i+1] ){
- change = arr[i+1];
- arr [i+1] = arr[i];
- arr [i] = change;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement