Q:

Write a C program to print all negative elements in an array

0

Write a C program to print all negative elements in an array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
#define MAX_SIZE 100 //Maximum size of the array

int main()
{
    int arr[MAX_SIZE]; //Declares an array size
    int i, num;

    //Enter size of array
    printf("Enter size of the array: ");
    scanf("%d", &num);

    //Reading elements of array
    printf("Enter elements in array: ");
    for(i=0; i<num; i++)
    {
        scanf("%d", &arr[i]);
    }

    printf("\nAll negative elements in array are: ");
    for(i=0; i<num; i++)
    {
        //Printing negative elements
        if(arr[i] < 0)
        {
            printf("%d\t", arr[i]);
        }
    }

    return 0;
}

Result:

Enter size of the array: 5

Enter elements in array: -2

-3

1

2

4

All negative elements in array are: -2  -3

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C program to count total number of negative ... >>