Hai...I am a very basic student for C...So many apologies for asking this basic question. My question is, How to write algorithm for the program to given n number is prime number? Please help.......
C Algorithm to Show n is a Prime Number
Collapse
X
-
Tags: None
-
-
As you know a prime number is one which can only be divided by 1 or itself.
So (ignoring these two) if the number can be divided by 2,3,5,7,9...... ...etc it is not prime. If not it is prime. I think that is the algorithm for determining whether a number is prime or not. Could you write some code to reflect this algorithm?
e.g.
Code:if(n%2==0)cout<<"n is not prime"<<endl;
Comment
Comment