Breaking

Friday, 4 August 2017

Print Odd Even Negative Integer Count

                  Print Odd Even Negative Integer Count

                                                 

Accept N integers and print the count of odd, even and negative integer count as the output.

Input Format:
The first line contains N.
The second line contains N integer values, separated by space.

Output Format:
The first line contains the count of odd, even and negative integer count separated by a space.

Boundary Conditions:
1 <= N <= 1000

Example Input/Output 1:
Input:
10
78 20 4 -12 96 93 15 60 -58 22

Output:
2 6 2

Example Input/Output 2:
Input:
20
-16 -32 87 79 -33 7 -8 87 63 25 84 39 -20 -12 84 98 8 28 22 74

Output:
7 7 6
Code:
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
int n,i,ele,odd=0,even=0,neg=0;
cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>ele;
        if(ele<0)  
            neg++;
        else if(ele%2==0)
            even++;
        else
            odd++;
    }
cout<<odd<<" "<<even<<" "<<neg;
}

Execute here, 

No comments:

Post a Comment

Like