Problem:- Program to count Number of the Positive and negative number in a 1-D integer Array. Means you have to count a positive and negative number in an Array
Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.
Logic:- For this problem simple fact you have to know that if the number is greater than zero then the number is positive if the number is less than the number is negative otherwise the number is zero. So for this problem, we have two variable one for positive number and another for the negative number and as I said above we compare the number with zero or if the number is greater than zero we will increase the positive variable by one for negative increase negative variable by one. Before solving follow C Program To Check Number Is Positive Or Negative
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post.
Solution:-
#include<iostream>
using namespace std;
int main()
{
int a[100],i,n,zero=0,pos=0,neg=0;
cout<<"Enter The Size of An Array :\n";
cin>>n;
cout<<"Enter The Element :\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Elment in Array is Given Below\n";
for(i=0;i<n;i++)
{
if(a[i]>0)
pos++;
else if(a[i]<0)
neg++;
else
zero++;
}
cout<<"\nPositive No. is = "<<pos;
cout<<"\nNegative No. is = "<<neg;
cout<<"\nTotal Zero in array is = "<<zero;
return 0;
}
Output:-
You May Also See
1. C++ Program To Merge One Accending And Another One Is Descending Array In Third Array Should be Descending Order
2.C Program To Find Row In An Array That Includes The Greatest Amount Of Even Number
3. C++ Program To Reverse An Array In O(n);
4. C++ Program To Convert A Lower Case To Upper Case
5. C++ Program To Print Reverse A Sentence
6. C++ Program To Print A Full String Input By Keyboard
7. C++ Program To Check String Is Palindrome Or Not
8. C++ Program To Find Cube Of Any Number Using Functions
9. C++ Program To Perform All Arithmetic Operations Using Functions
10. C++ Program To Find GCD (Greatest Common Divisor ) Using Functions
Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.
Logic:- For this problem simple fact you have to know that if the number is greater than zero then the number is positive if the number is less than the number is negative otherwise the number is zero. So for this problem, we have two variable one for positive number and another for the negative number and as I said above we compare the number with zero or if the number is greater than zero we will increase the positive variable by one for negative increase negative variable by one. Before solving follow C Program To Check Number Is Positive Or Negative
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post.
Solution:-
#include<iostream>
using namespace std;
int main()
{
int a[100],i,n,zero=0,pos=0,neg=0;
cout<<"Enter The Size of An Array :\n";
cin>>n;
cout<<"Enter The Element :\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Elment in Array is Given Below\n";
for(i=0;i<n;i++)
{
if(a[i]>0)
pos++;
else if(a[i]<0)
neg++;
else
zero++;
}
cout<<"\nPositive No. is = "<<pos;
cout<<"\nNegative No. is = "<<neg;
cout<<"\nTotal Zero in array is = "<<zero;
return 0;
}
Output:-
You May Also See
1. C++ Program To Merge One Accending And Another One Is Descending Array In Third Array Should be Descending Order
2.C Program To Find Row In An Array That Includes The Greatest Amount Of Even Number
3. C++ Program To Reverse An Array In O(n);
4. C++ Program To Convert A Lower Case To Upper Case
5. C++ Program To Print Reverse A Sentence
6. C++ Program To Print A Full String Input By Keyboard
7. C++ Program To Check String Is Palindrome Or Not
8. C++ Program To Find Cube Of Any Number Using Functions
9. C++ Program To Perform All Arithmetic Operations Using Functions
10. C++ Program To Find GCD (Greatest Common Divisor ) Using Functions
Below there is an Array of positive and negative number. Write a program that calculates how many of the numbers are positive and how many of them are negative. A [ ] = {10, -2, 9. -4, -6, -7, 12, 14, 19, -20}
ReplyDeleteYou are askig same Query. I think you are searching for C++ Program To Check Number Is Positive Or Negative If you have any Other Query send a Email.
ReplyDeleteYour Solution Is
/*
Below there is an Array of positive and negative number. Write a program that calculates how many of
the numbers are positive and how many of them are negative. A [ ] = {10, -2, 9. -4, -6, -7, 12, 14, 19, -20} on
*/
#include
#include
using namespace std;
int main()
{
int n, i,countneg = 0 , countpos = 0, countzero = 0;
cout<<"Enter The Array Size: ";
cin>>n;
int arr[n];
cout<<"\nEnter The Array Elements: \n";
for(i = 0; i < n; i++)
{
cin>>arr[i];
}
for(i = 0; i < n; i++)
{
if(arr[i]<0)
{
countneg++;
}
else if(arr[i]>0)
{
countpos++;
}
else
{
countzero++;
}
}
cout<<"\n\nTotal Number of Positive Elements in An Array is: "<<countpos;
cout<<"\nTotal Number of Negative Elements in An Array is: "<<countneg;
cout<<"\nTotal Number of Zero Elements in An Array is: "<<countzero;
return 0;
}
Header files are
Delete#include<iostream>
#include<cstring>
I don't know Why header files are not working....
DeleteHello, Sahni
Deletewe know that in Header file we use less than and greater than symbol, But this page compile the whole page except page body that is why header files are not showing. So don't worry about header file everybody knows header files in C/C++.