Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QtCore/QCoreApplication>
- #include<iostream>
- #include<windows.h>
- using namespace std;
- void ArrRandom(int ar[], int *pEnd, int modul);
- int character(int *pEnd,int ar[]);
- void newArr(int ar[],int *pEnd,int n);
- void SortArray(int ar[],int *pEnd);
- bool SortMod(int x1, int x2);
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- cout<<"Введите ограничение чисел ";
- int ar[80],modul, *pEnd=ar,*p;
- cin>>modul;
- cout<<endl;
- cout<<"Введите количество чисел массива ";
- int N;
- cin>>N;
- pEnd+=N;
- cout<<"Массив случайных чисел ";
- ArrRandom(ar,pEnd,modul);
- cout<<endl<<endl<<"Характеристика массива"<<endl;
- cout<<"Рiзниця мiж сумами парних та непарних чисел ";
- cout<<character(pEnd,ar);
- cout<<endl<<endl<<"Задайте на скiльки змiстити масив "<<endl;
- int n;
- cin>>n;
- //newArr(ar,pEnd,n);
- //for (int *p=ar;p<pEnd;p++)
- // cout<<*p<<" ";
- cout<<endl<<"Сортування за ускладненим правилом"<<endl;
- cout<<"Спочатку непарнi за зростанням, потiм парнi числа за спаданням ";
- SortArray(ar,pEnd);
- for(int *p=ar;p<pEnd;p++)
- cout<<*p<<" ";
- return a.exec();
- }
- void ArrRandom(int ar[], int *pEnd, int modul){
- for (int *p=ar;p<pEnd;p++){
- *p = rand()%modul;
- cout<<*p<<" ";}
- }
- int character(int *pEnd,int ar[]){
- int sum1=0,sum2=0;
- int *s1=&sum1,*s2=&sum2;
- for(int *p=ar;p<pEnd;p++)
- if(*p%2==0) *s1+=*p;
- else *s2+=*p;
- int rizn=*s1-*s2;
- return rizn;
- }
- void SortArray(int ar[],int *pEnd)
- {
- for(int *p1=ar; p1<pEnd-1; p1++)
- for(int *p2=p1; p2<pEnd; p2++)
- if(SortMod(*p1,*p2))
- swap(*p1,*p2);
- }
- bool SortMod(int x1, int x2)
- {
- if(x1%2 && x2%2)return x1>x2;
- else if(!(x1%2) && !(x2%2))return x1<x2;
- else return abs(x1%2)<abs(x2%2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement