program to sum only even numbers in c++ code example

Example: 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