Meena
BAN USER#include<stdio.h>
#define SIZE 9
void arrange(int[]);
void swap(int[],int,int);
int main()
{
int array1[SIZE]={-3,1,2,3,0,0,-2,-3,0};
arrange(array1);
int i=0;
for(;i<SIZE;i++)
{
printf("%d\t",array1[i]);
}
getchar();
return 0;
}
void arrange(int array1[])
{
int i = 0;
int first = 0,last = SIZE-1;
while(array1[i] <0)
{
i++;
}
while(i<=last)
{
if(array1[i]==0)
{
i++;
}
else
{
if(array1[i]>0)
{
swap(array1,i,last);
last--;
}
else
{
swap(array1,i,first);
first++;
}
}
}
}
void swap(int array1[ ],int first,int second)
{
int temp = array1[first];
array1[first]=array1[second];
array1[second]=temp;
}
#include<stdio.h>
# define SIZE 10
void arrange(int[]);
int main()
{
int array[SIZE] = {3,1,2,2,-2,-3,-2,6,2,3};
arrange(array);
int i;
for(i=0;i<SIZE;i++)
{
printf("\n%d",array[i]);
}
return 0;
}
void arrange(int array[])
{
if(SIZE > 0)
{
int first_n = 0,second_n = 0,pos = 0,i=0,j;
while(array[i]>=0 && i<SIZE)
{
i++;
}
pos = i;
while(i<SIZE)
{
while(array[i]<0 && i<SIZE)
{
i++;
}
if(i<SIZE)
{
first_n = array[pos];
array[pos] = array[i];
for(j=pos+1;j<i;j++)
{
second_n = array[j];
array[j] = first_n;
first_n = second_n;
}
array[i]=first_n;
i++;
pos = pos + 1;
}
}
}
}
- Meena October 15, 2013