# Answer to Question #11678 in C++ for Chad Dylan Cooper

Question #11678
Write a program that reads a set of integers (can be +ve or -ve) and then finds and prints the sum of the positive odd integers, negative even integers, and all integers not belonging to the previous two groups. (Use the following as test data: 1,2,3,4,5,-5,-4,-3,-2,-1,18,-18). You must make use a function named sumofNumbers that take an integer number that indicate how many numbers are in the test data and return the results (sum of positive odd integers, sum of negative even integers and sum of all integers which are not belonging to the previous two groups.
1
Expert's answer
2012-07-12T08:36:13-0400

#include <tchar.h>
#include <iostream>
using namespace std;

int* sumofNumbers(int n){
int* data = new int[n];
for(int i = 0; i < n; i++)
& cin >> data[i];
int* result = new int;
for(int i = 0; i < 3; i++)
& result[i] = 0;
for(int i = 0; i < n; i++)
& if((data[i] > 0)&&(data[i]%2 ==1))
& result += data[i];
& else if((data[i] < 0)&&(data[i]%2 == 0))
& result += data[i];
& else
& result += data[i];
return result;
}

int _tmain(int argc, _TCHAR* argv[])
{
int* result = sumofNumbers(12);
for(int i = 0; i < 3; i++)
& cout << result[i] << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

#### Comments

No comments. Be the first!

### Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS