Ask Question
26 June, 09:18

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.

+2
Answers (1)
  1. 26 June, 10:14
    0
    Answer:Following is the program for the count of negative integers in an array:-

    #include

    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"<
    cin>>n; //prompting the size of the array ...

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

    cout<<"Enter the numbers"<
    for (int i=0; i
    cin>>negative_nums[i]; //prompting elements of the array ...

    for (int i=0; i
    {

    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 "<
    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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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). ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers