//Count of +ve, -ve, zeroes and the smallest and largest number among it.
#include <iostream>
usingnamespace std;
int main()
{
longlongint range=0, cp=0, cn=0, cz=0, lpos=0, lneg=0, num, limit, lposs, lnegl, temp;
cout << "\nEnter the count of numbers you want to enter : ";
cin >> limit;
if (limit<=0)
{
cout << "Aborting !!!";
}
else
{
limit--;
cout << "Now enter the numbers : ";
do
{
cin >> num;
if (num>0)
{
cp++;
if (num>lpos)
{
lpos=num;
}
else
{
lposs=num;
}
}
elseif (num<0)
{
cn++;
if (num<lneg)
{
temp=num;
lneg=num;
if (temp>lneg)
{
lnegl=num;
}
}
}
else
{
cz++;
}
range++;
}
while (range<=limit);
cout << "The count of positive numbers is : " << cp;
cout << "\nThe count of negative numbers is : " << cn;
cout << "\nThe count of zeroes is : " << cz;
if (cp==0 && cz==0)
{
cout << "\nThe largest number is : " << lnegl;
}
elseif (cp==0 && cz>0)
{
cout << "\nThe largest number is : 0";
}
else
{
cout << "\nThe largest number is : " << lpos;
}
if (cn==0 && cz==0)
{
cout << "\nThe smallest number is : " << lposs;
}
elseif (cn==0 && cz>0)
{
cout <<"\nThe smallest number is : 0";
}
else
{
cout <<"\nThe smallest number is : " << lneg;
}
}
return main();
}
Sample Output:-
Enter the count of numbers you want to enter :3
Now enter the numbers : -4
-2
-3
The count of positive numbers is : 0
The count of negative numbers is : 3
The count of zeroes is : 0
The largest number is : -1 !!!The problem is here. Can you fix this.!!!
The smallest number is : -4
I don't want to use array in this program. So suggest me without using any array.
I want to find the largest and smallest number from user input values.
My program almost works fine.
If I input -4, -2, -3. The program shows -1 is the largest. This is not possible. the largest number is -2 but not -1. I just want to find the largest and smallest number among the list irrespective of negative or positive.