Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include<stdio.h>
  2. int is_prime(int m);
  3. int main(void){
  4. int i=1, count=0, n, coun, prime;
  5. FILE * fopen;
  6. fopen = fout("prime.txt","w");
  7.  
  8. fprintf(fout,"Enter a value: %d",n);
  9. fscanf(fout,"%d",&n);
  10. fprintf(fout,"count prime");
  11.  
  12. i=1;
  13. count=0;
  14. while(count<n){
  15. if(is_prime(i)==1){
  16. count++;
  17. fprintf(fout,"5%d 5%d", coun, prime);
  18. }
  19. i++;
  20. }
  21. fclose(fout);
  22. return 0;
  23. }
  24.  
  25. int is_prime(int m)
  26. {
  27. int k, limit;
  28. int result;
  29.  
  30.  
  31. if (m == 1) {
  32. result = 0; /* 1 is not prime */
  33. } else if (m == 2) {
  34. result = 1; /* 2 is the only even prime */
  35. } else if (m % 2 == 0) {
  36. result = 0; /* even numbers > 2 are not prime */
  37. } else {
  38. result = 1; /* start off assuming that m is prime */
  39. limit = m/2; /* check up to 1/2 of the number */
  40. for( k = 3; k <= limit; k = k + 2 ){
  41. if( (m % k) == 0 ){
  42. result = 0;
  43. break;
  44. }
  45. }
  46. }
  47.  
  48.  
  49. return result;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement