To display only the negative elements of the array
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20], i, n;
clrscr();
printf("Enter the limit : ");
scanf("%d", &n);
printf("\nEnter the elements :\n\n");
for(i = 0 ; i < n ; i++)
scanf("%d", &a[i]);
printf("\nThe negative elements are :\n\n");
for(i = 0 ; i < n ; i++)
{
if(a[i] < 0)
printf("%d\t", a[i]);
}
getch();
}
Output:
Enter the limit : 5
Enter the elements :
10 -20 30 -40 -50
The negative elements are :
-20 -40 -50
-
UpdatedDec 30, 2019
-
Views5,245
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order