Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- bool podredi(int i,int j){
- return(i<j);
- }
- void fillarray(int ina[],int in,int R,int s,int a=0){
- if (R == 1)
- for (int i=0;i<in;i++){
- ina[i]=rand() % s;
- }
- else if (R== 0)
- for (int i=0;i<in;i++){
- cout<<"["<<i<<"] = ";
- cin>>a;
- ina[i]=a;
- }
- else
- cout<<"Wrong random switch"<<endl;
- }
- void printar(int a[],int m){
- for(int i=0; i<m; i++){
- if (a[i]!=0)
- cout<<a[i]<<endl;
- }}
- int main()
- {
- //By viktor korunoski 05-12-2019
- int n,r=0,s=0,zb;
- char p;
- float c=0;
- cout << "Number elements in the array: ";
- cin>>n;
- cout<<endl;
- cout<<"Random? Y/N"<<endl;
- cin>>p;
- zb=0;
- if ((p == 'Y') or (p== 'y')){
- r=1;
- cout<<"From 0 to ";
- cin>>s;
- cout<<endl;
- }
- else if((p == 'N') or (p == 'n'))
- r=0;
- else
- cout<<"Wrong random swithch"<<endl;
- int b[n],ap[n],apm[n];
- fillarray(b,n,r,s);
- for (int i=0;i<n;i++){
- apm[i]=0;
- ap[i]=0;
- zb=zb+b[i];
- }
- c=zb/(n-1);
- for(int i=0; i<n; i++){
- if(b[i]<c){
- ap[i]=b[i];
- }
- else
- apm[i]=b[i];
- }
- sort(ap,ap+n,podredi);
- sort(apm,apm+n);
- cout<<"Larger then the avreage "<<endl;
- printar(ap,n);
- cout<<" "<<endl;
- cout<<"Smaller than the avreage "<<endl;
- printar(apm,n);
- cout<<" "<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement