Program to separate positive and negative numbers in an array
#include<iostream>
#include<conio.h>
using namespace std;
void separateposneg(int arr[10],int a)
{
int j=0,b[10],count=0;
for(int i=0;i<a;i++)
{
if(arr[i]>0)
{
count++;
b[j]=arr[i];
j++;
}
}
for(int i=0;i<a;i++)
{
if(arr[i]<0)
{
b[count]=arr[i];
count++;
}
}
cout<<"The separated numbers are\n";
for(int j=0;j<a;j++)
{
cout<<b[j]<<"\n";
}
}
int main()
{
int ar[10],n;
cout<<"enter no of values\n";
cin>>n;
cout<<"Enter array\n";
for(int i=0;i<n;i++)
{
cin>>ar[i];
}
separateposneg(ar,n);
getch();
}
Input : 6
3 90 -2 6 -90 5
Output :
3 90 6 5 -2 -90
Comments
Post a Comment