+ 3
write a program to enter the numbers till the user wants & at the end it should display the count of +ve,-ve & zeroentered
2 Answers
+ 4
#include <iostream>
using namespace std ;
int main ()
{
int num, positive=0, zero=0, negative=0 ;
char another ;
do
{
cout << "enter a number " ;
cin >> num ;
if (num>0)
positive++ ;
else if (num==0)
zero++ ;
else if (num<0)
negative++ ;
cout << "No. of +ve no.s= " << positive << endl ;
cout << "No. of zeros= " << zero << endl ;
cout << "No. of -ve no.s= " << negative << endl ;
cout << "Do you want to enter another number y/n " ;
cin >> another ;
} while (another=='y') ;
return 0 ;
}
+ 1
#include <iostream>
using namespace std;
int main ()
{
int num;
int positive=0,negative=0,zero=0;
while(1)
{
cin>>num;
if (num>0)
positive++;
else if (num <0)
negative++;
else if (num==0)
zero++;
else
break;
}
cout<<"+ve numbers = "<< positive <<endl;
cout<<"-ve numbers = "<< negative <<endl;
cout<<"number of zeros = "<< zero <<endl;
return 0;
}