In: Computer Science
main() gets user input for size and elements of arr[].
. Check each element for negative, positive and zero and create
neg[], pos[] and zer[] accordingly in main() only.
C program :-
#include<stdio.h>
int main() {
int size;
printf("\nEnter the size of array :");
scanf("%d",&size);
int arr[size];
int pos[size];
int p_count=0;
int neg[size];
int n_count=0;
int zer[size];
int z_count=0;
for(int i=0; i<size; i++){
printf("\nenter an integer :");
scanf("%d",&arr[i]);
}
for(int i=0; i<size; i++){
if(arr[i]>0){
pos[p_count]=arr[i];
p_count++;
}
else if(arr[i]<0){
neg[n_count]=arr[i];
n_count++;
}
else{
zer[z_count]=arr[i];
z_count++;
}
}
printf("\n\nThe positive array :");
for(int i=0; i<p_count; i++){
printf("\nPositive element: %d",pos[i]);
}
printf("\n\nThe negative array :");
for(int i=0; i<n_count; i++){
printf("\nNegative element: %d",neg[i]);
}
printf("\n\nThe Zero array :");
for(int i=0; i<z_count; i++){
printf("\nZero element: %d",zer[i]);
}
}
Output:-