Write C program to count total number of negative elements in array


Introduction

Write C program to count total number of negative elements in array


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>

int main()
{
    int arr[100]; //Declaring size of an array as 100
    int i, num, count=0;

    //Reads size and elements of array

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

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

    //Counts total number of negative elements
    for(i=0; i<num; i++)
    {
        if(arr[i]<0)
        {
            count++; //couting negative elements
        }
    }
    printf("\nTotal number of negative elements = %d", count);

    return 0;
}

Result

C language

     





Related Topics




Popular Posts