First off, you need to learn how to indent code.
Code:
#include<stdio.h>
int main()
{
int a[8] = { 1, 8, 2, -3, 4, -5, -6, -7 };
int i, j, n;
int k = 0, l = 0, p = 0, q = 0;
int pos[8], neg[8];
clrscr();
for (j = 0; j < 8; j++) {
if (a[j] >= 0) {
pos[k] = a[j];
k++;
} else {
neg[l] = a[j];
l++;
}
}
for (i = 0; i < 8; i++) {
if (i % 2 == 0) {
if (pos[p] == '\n')
continue;
else {
printf(" %d ", pos[p]);
p++;
}
} else {
if (neg[q] == '\n')
continue;
else {
printf(" %d ", neg[q]);
q++;
}
}
}
}
Second, your name isn't a proper thread title.
How To Ask Questions The Smart Way
> if (pos[p] == '\n')
What do you expect this to do?
'\n' has the decimal value 10, but that appears nowhere in your data.
Perhaps more meaningful variable names would help, for example
Code:
for (j = 0; j < 8; j++) {
if (a[j] >= 0) {
positiveElements[numPositives] = a[j];
numPositives++;
} else {
negativeElements[numNegatives] = a[j];
numNegatives++;
}
}
Now use numPositives and numNegatives in your next loop to determine if you should print something from the corresponding array.