When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
4 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
the code itself
#include <iostream>
#include <vector>
#include <set>
using namespace std;
void find_prime(int A, int B, set<int>& factors, int depth) {
cout << "Recursion #" << depth << ": A = " << A << endl;
for (int i = 2; i <= A/2; i++) {
if (A % i == 0 ) {
if (i % 10 != B) {
factors.insert(i);
}
return find_prime(A / i, B, factors, depth+1);
}
}
}
int main() {
int A;
cout << "Enter A: ";
cin >> A;
int B;
cout << "Enter B: ";
cin >> B;
int depth = 1;
set<int> factors;
find_prime(A, B, factors, depth);
cout << "Prime numbers of " << A << ", that don't end with " << B << ": ";
for (int factor : factors) {
cout << factor << " ";
}
return 0;
}
it needs to have also 31
need help finding prime factors with recursion