Array is defined in the code and we should count the number of positive numbers in the array and create a new array and insert all the positive numbers in it if the positive numbers in the original array is bigger than the negative numbers in the original array and if if the oppisite (negative numbers bigger than positive numbers we create a new array and insert all the negative numbers )
and if its equal (postive numbers and negative numbers ) we create a new array and insert first all the postive number and then all the negative numbers
*we must create the array in the function with malloc..
the code :
#include <stdio.h>
#define n 10
void func(int *arr)
{
int i,j,c1=0,c2=0,mat;
for(i=0;i<n;i++)
{
if (*arr>=0) c1++;
else c2++;
arr++;
}
if(c1>c2)
{
mat=(int *)malloc(c1*sizeof(int));
for(i=0;i<c1;i++)
if(*arr>0)
{
mat=*arr;
mat++;
arr++;
}
}
else if(c2>c1)
{
mat=(int *)malloc(c2*sizeof(int));
for(i=0;i<c2;i++)
if(*arr<0)
{
mat=*arr;
mat++;
arr++;
}
}
else
{
mat=(int *)malloc((c1+c2)*sizeof(int));
for(i=0;i<n;i++)
if(*arr>0)
{
mat=*arr;
mat++;
arr++;
}
for(i=0;i<n;i++)
if(*arr<0)
{
mat=*arr;
mat++;
arr++;
}
}
}
main()
{
int array={6,3,5,-5,4,3,-6,-9,6,-16};
int *arr=array;
func(arr);
}