F
Freyr
Hello,
I'm taking an independant course in C++, and one of my questions asks
to use the following algorithm to deturmine the factors of any given
number:
--
Initialize a counter at 2
So Long as long as the counter is less than or equal to the number
if the counter divides the number evenly
display the counter
divide the number by the counter to get a new number
else
add one to the counter
--
I don't know exactly what "divide the number by the counter to get a
new number" is asking.
This is the code I have so far, I know it's incomplete and not close,
but I am completly lost.
/* 4-31 Exercise 12 - A program to display prime factors */
#include <iostream>
using namespace std;
main() {
int Number;
cout << "Enter Starting Number: ";
cin >> Number;
cout << "Prime Factors: "
for(int n=2; n <= Number {
if(Number%n == 0){
cout << n;
}
else {
n++;
}
}
}
If you're wondering about school/project cheating, my teacher asked me
to post this, she doesn't know C++.
Thanks alot
-Freyr
I'm taking an independant course in C++, and one of my questions asks
to use the following algorithm to deturmine the factors of any given
number:
--
Initialize a counter at 2
So Long as long as the counter is less than or equal to the number
if the counter divides the number evenly
display the counter
divide the number by the counter to get a new number
else
add one to the counter
--
I don't know exactly what "divide the number by the counter to get a
new number" is asking.
This is the code I have so far, I know it's incomplete and not close,
but I am completly lost.
/* 4-31 Exercise 12 - A program to display prime factors */
#include <iostream>
using namespace std;
main() {
int Number;
cout << "Enter Starting Number: ";
cin >> Number;
cout << "Prime Factors: "
for(int n=2; n <= Number {
if(Number%n == 0){
cout << n;
}
else {
n++;
}
}
}
If you're wondering about school/project cheating, my teacher asked me
to post this, she doesn't know C++.
Thanks alot
-Freyr