C++ Saved Program: serene-home

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


// C++ program to Move All -ve Element At End
// Without changing order Of Array Element
#include<bits/stdc++.h>
using namespace std;


void funct(int a[],int size)
{
    int i=0,j,t;
    while(i<size)
    {
        if(a[i]<0)
        {   
            j=i;
            while(a[j]>0)
            {
                j++;
            }
            t=a[i];
            a[i]=a[j];
            a[j]=t;
            
        }
    }
       
    
}

int main()
{
	int arr[] = {1 ,-1 ,-3 , -2, 7, 5, 11, 6 };
	int n = sizeof(arr)/sizeof(arr[0]);
    
    funct(arr,n);
    for(int i=0;i<n;i++)
    cout<<arr[i]<<endl; 
	return 0;
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs