Ask Question
28 June, 04:40

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.

+1
Answers (1)
  1. 28 June, 07:12
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers