i have a hard time to convert my c++ program into flowchart...
any idea on how to convert my c++ program into flowchart?
heres my source code and problem:
find five four prime digit no. such that the product of 4 prime digit no. is also prime:
#include <iostream>
#include <vector>
using namespace std;
void main(){
vector <int> primelist;
for (int i=1000; i<10000; i++){
if (i%2 == 0 && i != 2 || i%5 == 0 && i != 5) // all straight numbers and numbers with 0 or 5 ending cant be prime numbers
continue;
bool prime=true;
for (int j=2;j<i;j++){
if (i%j == 0){
prime=false;
break;
}
}
int tmp = i,product=1;
int primearray[4];
for (int k=0; k<4;k++){ // get the 4 digits of the number
primearray[k] = tmp%10;
tmp = tmp/10;
}
for (int k=0;k<4;k++){
product *= primearray[k]; //multiply the 4 numbers
}
if (product == 0)
prime = false;
else{
for (int l=2;l<product;l++){ //repeat prime check for the product of each number
if (product%l == 0){
prime=false;
break;
}
}
}
if (prime && primelist.size()<6)
primelist.push_back(i);
}
cout << "Found following prime numbers " << endl;
for (int m=0;m<5;m++){
cout << primelist[m] << " ";
}
(system"pause");
}
what??????? You really need to take some time and think about the definition of prime number. Multiplication has nothing to do with it. A number is prime IF AND ONLY IF the number has exactly 2 divisors and the divisors are not the same.
3 is prime: its divisors are 1 and 3. <--- 2 divisors
5 is prime: its divisors are 1 and 5.
1 is NOT prime: its only divisor is 1. <--- less than 2 divisors
0 is NOT prime: it has no divisors. EDIT: 0 has infinitely many divisors (but not itself)
6 is NOT prime: its divisors are 1, 2, 3, and 6. <--- more than 2 divisors