Guest User

Untitled

a guest
Nov 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define TRUE 1
  5. #define FALSE 0
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. FILE *in;
  10. int a, d, n;
  11. int number;
  12.  
  13. if (argc != 2) {
  14. fprintf(stderr, "usage: %s file\n", argv[0]);
  15. exit(1);
  16. }
  17.  
  18. if ((in = fopen(argv[1], "r")) == NULL) {
  19. fprintf(stderr, "cannot open %s\n", argv[0]);
  20. }
  21.  
  22. while (1) {
  23. fscanf(in, "%d %d %d", &a, &d, &n);
  24. if (a == 0 && d == 0 && n == 0) {
  25. break;
  26. }
  27. number = a;
  28. while (n != 0) {
  29. if (isPrime(number) == TRUE) {
  30. if (n == 1) {
  31. printf("%d\n", number);
  32. break;
  33. }
  34. n --;
  35. }
  36. number += d;
  37. }
  38. }
  39. }
  40.  
  41. int isPrime(int x)
  42. {
  43. int i;
  44.  
  45. if (x == 1) {
  46. return FALSE;
  47. }
  48. for (i = 2; i < x; i ++) {
  49. if (x % i == 0) {
  50. return FALSE;
  51. }
  52. }
  53. return TRUE;
  54. }
Add Comment
Please, Sign In to add comment