count and list a divisible number in array

I posted this in another section but no one replied so I am hoping someone can help me on this section.

Hi. I need to create an array 10 x 10 numbers from 1-1000. Then enter a number that is evenly divisible. Then print a single dimension array to evenly divisible numbers. I found a solution on this board but they used vectors which we have not covered in class. I am stuck on the getDivisible and printarray of divisible number part.

It runs but it says there are 0 evenly divisible numbers.

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
60
61
62
63
64
65
#include <iostream>

using namespace std;

void fill2DArray(int a[][10], int size);
void print2DArray(int a[][10], int size);
int getDivisible(int ar[][10], int size, int num);


int main()
{
	int ar[10][10];
	int count = 0;
	fill2DArray(ar, 10);
	print2DArray(ar, 10);

	int num;
	cout << "Enter a number to divide by" << endl;
	cin >> num;

	getDivisible(ar, 10, num);
	cout << "There are " << count << " evenly divisible numbers. They are : " << endl;
	cout << endl;

	return 0;
}

void fill2DArray(int a[][10], int size)
{
	for (int row = 0; row < 10; row++)
	{
		for (int col = 0; col < 10; col++)
		{
			a[row][col] = rand() % 1000 + 1;
		}
	}
}

void print2DArray(int a[][10], int size)
{
	for (int row = 0; row < 10; row++)
	{
		for (int col = 0; col < 10; col++)
		{
			cout << a[row][col] << "\t";
		}
		cout << endl;
	}
}

int getDivisible(int ar[][10], int size, int num)
{
	int count = 0;
	for (int row = 0; row < size; row++)
	{
		for (int col = 0; col < 10; col++)
		{
			if ((ar[row][col]) % num == 0)
			{
				count++;
			}
		}
	}
	return count;
}
Last edited on
Topic archived. No new replies allowed.