how to add even odd in c++ code example

Example 1: even and odd in c++

#include <iostream>
using namespace std;

int main()
{
	int n;
	cout << "Enter an integer: ";
	cin >> n;
	(n % 2 == 0) ? cout << n << " Is Even." : cout << n << " Is Odd.";
}

Example 2: c++ sum of even and odd numbers

//given the fact that it takes n of number
void sumEvenAndOdd(){
int n=0 , evenSum=0 , oddSum=0;
     int numbers[Size];
     cout<<"enters the number(N) of integers\n";
     cin>>Size;

     cout<<"Enter "<<Size<<" number/s:\n";
     for(int i =0 ;i< Size ; ++i){
        cin>>numbers[i];
     }
     for(int i =0 ;i<Size ; ++i){
        if(numbers[i]%2 ==0){
            evenSum += numbers[i];
        }
        else{
            oddSum += numbers[i];
        }
     }
     cout<<"the sum of even numbers is : "<<evenSum <<"\nthe sum of odd numbers is :"<<oddSum<<endl;
}

Tags:

Cpp Example