Guys, paano ba ito? Di ko kasi magets eh. Di ko kasi pwedeng galawin yung int main.

Create a program in C++ that will store 10 values in an array. Determine how many are odd and how
many are even numbers from the given values and store them in separate arrays, one array that will hold
all even numbers, and another array that will hold odd numbers. Display the values of the 2 arrays.

SAMPLE DIALOGUE
Type 10 numbers: 1
2 3 4 5 6 7 8 9 10
EVEN array values:
2 4 6 8 10
___
ODD array values:
1 3 5 7 9

int main(){

int num[10]; //this will hold 10 numbers

int evenSize=0, oddSize=0; //this will hold the number of even and odd numbers respectively

askValues(num); //this will ask 10 values to be stored in the array

evenSize=countEven(num); //this function will return the number of even values

oddSize=countOdd(num); //this function will return the number of odd values

int even[evenSize]; //creates the array that will hold even numbers

int odd[oddSize]; //creates the array that will hold odd numbers

copyEven(num,even); //this function will copy all even numbers from 1st array to 2nd array

copyOdd(num,odd); //this function will copy all odd numbers from 1st array to 2nd array

dispArrayValues(even,evenSize); //this function will display values of the array

dispArrayValues(odd,oddSize);

return 0;
}
Well at least the post is in English. Have you attempted to write any of the functions? All I'm gonna say is you'll need a for loop to:
1) push_back the values into each array, and
2) output the values of each array at their respective indices.
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;

void askValues(int[]);
int countEven(int[]);

const int LIMIT = 10;

int main() {

	int num[LIMIT]; //this will hold 10 numbers

	int evenSize = 0, oddSize = 0; //this will hold the number of even and odd numbers respectively

	askValues(num); //this will ask 10 values to be stored in the array

	evenSize = countEven(num); //this function will return the number of even values

	cout << "There are " << evenSize << " even numbers in the array." << endl;
	//oddSize = countOdd(num); //this function will return the number of odd values

	//int even[evenSize]; //creates the array that will hold even numbers
	//int odd[oddSize]; //creates the array that will hold odd numbers

	//copyEven(num, even); //this function will copy all even numbers from 1st array to 2nd array
	//copyOdd(num, odd); //this function will copy all odd numbers from 1st array to 2nd array

	//dispArrayValues(even, evenSize); //this function will display values of the array
	//dispArrayValues(odd, oddSize);

	return 0;
}

void askValues(int num[])
{
	for (int i = 0; i < LIMIT; i++)
	{
		cout << "Please enter a number: ";
			cin >> num[i];
	}
	return;
}

int countEven(int num[])
{
	int count = 0;

	for (int i = 0; i < LIMIT; i++)
	{
		if (num[i] / 2 == 0)
			count++;
	}

	return count;
}
Last edited on
Topic archived. No new replies allowed.