Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
a program that counts for the number of primes less than a given natural numbers.
Posted
Updated 12-Dec-11 2:44am
v2

Wow, it looks a fresh problem, I suppose it hasn't ever faced by nobody, hence you can't find anything on Google about it[^].
 
Share this answer
 
Comments
Stefan_Lang 12-Dec-11 12:25pm    
+5 for the enthusiasm! :-D
#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int n;
    cin>>n;
    for(i=2;i<=n/2;i++)
    {
        if(n%i==0)
        {
            cout<<"the no. is not prime";
            break;
        }
    }
    if(i>n/2)
    {
        cout<<"no. is prime";
    }
    getch();
}
 
Share this answer
 
v2
Comments
Albert Holguin 12-Dec-11 10:22am    
I added some formatting, but your code is pseudo-code at best (wouldn't even compile).
 
Share this answer
 
Comments
Dani_k 12-Dec-11 8:51am    
i appreciate you saying that but at least help me what condition i put in the for loop for this problem
Stefan_Lang 13-Dec-11 5:48am    
Come on! You posted the condition right in your question! Start thinking for yourself.
Keith Barrow 14-Dec-11 4:20am    
I wish I could 5 this comment.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900