c++ goes flowcharting

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");
}
wtf?

The product of any two integers a and b is by definition not prime unless a and b are both 1, or one is 1 and
the other 2, or one of them is 0.
closed account (z05DSL3A)
but 1 is also not a prime...
but i think 1 is a prime...
Let me google that for you: http://lmgtfy.com/?q=is+one+prime%3F&l=1

HTH
http://upload.wikimedia.org/wikipedia/en/d/d6/FlowchartExample.png
flowcharts are supposed to be easier than code...

Your if statement needs i%3, i%7, i%11, etc if you want to do it that way.

Your last line of code is wrong.

and use code tags, **Things I deleted** (the # icon on the right).

ONE IS NOT A PRIME. It doesn't matter what you think.

Wikipedia:
A natural number is called a prime, a prime number or just prime if it has exactly two distinct divisors.


It is defined thus, so that there can be a unique prime number factorization for every integer. Along with many other happy math things.

As jmsith pointed out: products of integers are not usually prime. It is in fact rare i.e. p*1 where p is prime is the only case.
Last edited on
only by definition that the # 1 is not prime...

but if we put a prime no. like 3..7.. one is considered to be prime since 1 is multiplied by a prime no..


anyways i have a question
why is it that 0 and 5 are straight no.?
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

and what is a "straight" number?
Last edited on
Not to argue but doesn't 0 has infinite divisors?
Either way it's not prime
Ya, that was stupid. I was thinking about not dividing by zero.
Topic archived. No new replies allowed.