Advertisement
DBP625

Counting even,odd,positive or negative from n number

Apr 6th, 2022
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,Ev=0,Od=0,Po=0,Ne=0;
  6. cin>>t;
  7. for(int i=1;i<=t;i++)
  8. {
  9.     int x;
  10.     cin>>x;
  11.     if(x<0)
  12.     {
  13.         Ne+=1;
  14.     }
  15.     else
  16.     {
  17.         if(x%2==0)
  18.         {
  19.             Ev+=1;
  20.         }
  21.         else if(x%2!=0)
  22.         {
  23.             Od+=1;
  24.         }
  25.         else if(x>0)
  26.         {
  27.             Po+=1;
  28.         }
  29.     }
  30. }
  31. cout<<"Even: "<<Ev<<endl<<"Odd: "<<Od<<endl<<"Positive: "<<Po<<endl<<"Negative: "<<Ne<<endl;
  32. }
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement