Print all negative elements in an array with C.
#include <stdio.h>
int main()
{
int arr[101];
int i, N;
printf("Enter size of the array : ");
scanf("%d", &N);
printf("Enter elements in array : ");
for (i = 0; i < N; i++)
{
scanf("%d", &arr[i]);
}
printf("\nAll negative elements in array are : ");
for (i = 0; i < N; i++)
{
if (arr[i] < 0)
{
printf("%d ", arr[i]);
}
}
return 0;
}
Output:-
Enter size of the array : 10
Enter elements in array : -2 5 -4 6 -7 8 4 -5 -3 9
All negative elements in array are : -2 -4 -7 -5 -3
0 Comments