Quick actions

cmd+k|ctrl+k

Navigation

Languages

Separating Negative Integers From Positive

Snippet info

Language

Cpp

Visibility

public

Author

amangoyal1727

Created

2021-01-07T16:44:15Z

Updated

2021-01-07T16:44:15Z

#include <iostream>
using namespace std;

int main() {
    int n;
    cin>>n;
    int k =0;
    int A[n];
    int l = n-1;
    for(int i =0 ; i<n; i++){
        cin>>A[i];
    }
    
    int B[n];
    for(int j=0 ; j<n; j++) {
        if(A[j]<0){
            B[k++]=A[j];
        }
        else
            B[l--]=A[j];
    }
    
    for (int k=0; k<n;k++){
        cout<<B[k]<<" ";
    }
    
    
}
INFO