Advertisement
Guest User

Untitled

a guest
Apr 25th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int isPrime(long);
  5.  
  6. int main(){
  7.    long c,t=3;
  8.    for(c=1;c<=10001;t+=2)if(isPrime(t))c++;
  9.    printf("%d\n", t);
  10.    return 0;
  11. }
  12.  
  13. int isPrime(long x){
  14.    int i;
  15.    
  16.    if(x==2||x==3)  return 1;    //if i = 2 or 3, return true
  17.    if(!(x&1))      return 0;    //if x is even  return false
  18.  
  19. //if x is divisible by i return false  
  20.    for(i=3;i<=sqrt(x);i+=2)if (x%i == 0) return 0;
  21.    
  22.    return 1;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement