17. Program that takes n numbers as input. It displays total positive and negative numbers.

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 17:

Write a program that takes n numbers as input. It displays total positive and negative numbers.

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int n, num, count, p_num=0, n_num=0;
    cout<<"Enter the number upto which you want to enter numbers:";
    cin>>n;
    for(count=1;count<=n;count++)
    {
        cout<<"\nEnter a number:";
        cin>>num;
        if(num>=0)
        p_num++;
        else
        n_num++;
    }
    cout<<"\nTotal positive numbers enetered by the user are:"<<p_num;
    cout<<"\nTotal negative numbers enetered by the user are:"<<n_num;  
    return 0;
}

Let me know in the comment section if you have any question.

Previous Post:
16. Program that continuously inputs positive integer values from the user. The program should finally display the second largest number entered.

Comments