Created
July 20, 2013 05:23
-
-
Save rfaisal/6043966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<math.h> | |
| int is_prime(int p){ | |
| if(p<=1) return 0; | |
| int i=2; | |
| int sqrt_p=sqrt(p); | |
| while(i<=sqrt_p) | |
| if(p%i++==0) | |
| return 0; | |
| return 1; | |
| } | |
| /** | |
| * USAGE: ./a.out 10001 | |
| **/ | |
| int main(int argc, char *argv[]){ | |
| if(argc<2) return 1; | |
| int total = atoi(argv[1]); | |
| int i=1; | |
| int count=0; | |
| while(count<total){ | |
| if(is_prime(i)) count++; | |
| i++; | |
| } | |
| return i-1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment