[ create a new paste ] login | about

Link: http://codepad.org/TDvuEcAD    [ raw code | output | fork ]

C++, pasted on Nov 13:
#include <stdio.h>
#include <stdlib.h>

#define N 50

void swap(int& n1, int& n2);

int main(int argc, char* argv[])
{
	int A[N] = { 0 };
	for (int t = 0; t < N; t++)
	{
		A[t] = rand() % 40 - 20;
		if (A[t] == 0) A[t]++;
		printf("%d ",A[t]);
	}

	printf("\n");

	for (int i = 0; i < N; i++)
		for (int r = i+1; r < N && A[i] < 0; r++)
			if (A[r] > 0) swap(A[i],A[r]);

	for (int z = 0; z < N; z++)
		printf("%d ",A[z]);

	printf("\n");

	return 0;
}

void swap(int& n1, int& n2)
 { int _tn = n1; n1 = n2; n2 = _tn; }


Output:
1
2
3 -14 -3 15 13 -5 6 -8 -11 1 -18 7 -10 -1 -17 -14 1 6 -8 -4 -9 -12 -13 9 2 -10 2 -17 7 -5 -11 -18 2 -2 9 -13 13 -4 -9 -18 9 -7 1 19 4 -3 18 -16 15 -10 
3 15 13 6 1 7 1 6 9 2 2 7 2 9 13 9 1 19 4 18 15 -12 -13 -11 -3 -10 -18 -17 -5 -5 -11 -18 -10 -2 -1 -13 -17 -4 -9 -18 -14 -7 -14 -8 -8 -3 -4 -16 -9 -10 


Create a new paste based on this one


Comments: