C++ = Write a program that takes n numbers as input. It displays total positive and negative numbers.
Code:
#include <iostream>
using namespace std;
int main()
{
int num,pos=0,neg=0;
cout<<"Enter the number of numbers to be input : ";
cin>>num;
for (int i=1;i<=num;i++) //1 //2
{
int n;
cin>>n;
if (n>0)
{
pos++;
}
else
{
neg++;
}
}
cout<<"The number of positive numbers you entered are "<<pos<<endl;
cout<<"The number of negative numbers you entered are "<<neg<<endl;
return 0;
}
Result:
Comments
Post a Comment