Print positive and negative elements separately in array

#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,a[25];
clrscr();
printf("Enter number of elements");
scanf("%d",&n);
printf("Enter elements of array");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}

printf("\n Negative Elements : \n");
for(i=0;i<n;i++)
{
     if(a[i]<0)
     printf("\n%d",a[i]);
}

printf("\n Positive Elements : \n");
for(i=0;i<n;i++)
{
     if(a[i]>0)
     printf("\n%d",a[i]);
}
getch();
return 0;
}

0 comments:

Post a Comment