Write a C++ program that takes as input a list ( an array) of n integrers and finds the number of negative inetgers inthe list (array ).
Side Note: The problem did not come out ofthis book but the information that I study is from this book. And Iam not getting how to write the program.

Respuesta :

Answer:Following is the program for the count of negative integers in an array:-

#include <bits/stdc++.h>  

using namespace std;

int main()

{

   int n,count=0;//declaring 2 variables n and count and initializing count with 0..

   cout<<"Enter the size of the array"<<endl;

   cin>>n;//prompting the size of the array...

   int negative_nums[n];//array of integers of size n..

   cout<<"Enter the numbers"<<endl;

   for(int i=0;i<n;i++)

   cin>>negative_nums[i];//prompting elements of the array...

   for(int i=0;i<n;i++)//iterating over the array....

   {

       if(negative_nums[i]<0)// if integer in the array at ith position is negative...  

       count++;// increasing the count...

   }

   cout<<"The number of negative numbers are "<<count<<endl;//printing the count of negative integers...

   return 0;

}

Explanation:

1. In the program i have taken a count integer initializing it with 0

2. Iterating over the array.

3. If the element at ith position is less than zero then increasing the count by 1.

4.Printing the count of negative integers in the array.