You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Q-An array contains both positive and negative numbers in random order. Rearrange the array elements so that all negative numbers appear before all positive numbers.
//Note: Order of elements is not important here.
#include <iostream>
using namespace std;
int main() {
int a[]={1,5,4,-9,-1,-21,-58,1},i,j;
int n=sizeof(a)/sizeof(a[0]);
//iterating array with i
for(i=0;i<n;i++)
{
if(a[i]>0)
{
//if a[i] is positive & any element after a[i] is negative swap it with a[i]