-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheven_prime_finder_matrix.cpp
103 lines (71 loc) · 1.38 KB
/
even_prime_finder_matrix.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
using namespace std;
int main()
{
int matrix[5][5], even_count = 0, prime_count = 0, count = 0, num = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
cout << "Enter number in the index [" << i << "] [" << j << "] : ";
cin >> matrix[i][j];
}
}
cout << endl;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
cout << matrix[i][j] << " ";
}
cout << endl;
}
cout << "\n\nRow ";
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (matrix[i][j] != 1 && matrix[i][j] != 0) {
if (matrix[i][j] % 2 == 0)
{
even_count++;
}
}
}
if (even_count > 1)
{
cout << i << " ";
}
even_count = 0;
}
cout << " contains 2 or more even numbers" << endl << endl;
cout << "Row ";
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
num = matrix[i][j];
for (int k = 2; k < num; k++)
{
if (num % k == 0) {
break;
}
else if (num == k + 1) {
prime_count++;
count++;
}
}
}
if (prime_count < 2)
{
cout << i << " ";
}
prime_count = 0;
}
cout << " has less than 2 prime numbers \n\n";
if (count == 0) {
cout << "No row found containing two prime numbers" << endl << endl;
}
system("pause");
return 0;
}