Advertisement
triclops200

isPrime

Sep 21st, 2011
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int isprime(int n){
  4.     if(n%2==0)
  5.         return 0;
  6.     int a;
  7.     for(a=3;a <= sqrt(n)+1;a+=2){
  8.         if(n%a==0)
  9.             return 0;
  10.     }
  11.     return 1;
  12. }
  13. int main(){
  14.     char c[1];
  15.     int count = 1;
  16.     int n;
  17.     for(n=3;n <= 1000000; n++)
  18.         if(isprime(n) == 1)
  19.             count++;
  20.     printf("%d",count);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement