kokusz19

2017.04.19.Primszam(D)

May 28th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6.  
  7. int prime(int *tomb, int db)
  8. {
  9. int i, j, primszam=1;
  10.  
  11.  
  12.  
  13. for(i=0;i<db;i++)
  14. {
  15. if(tomb[i]<2)
  16. primszam++;
  17. for(j=2;j<sqrt(tomb[i]);j++)
  18. {
  19. if(tomb[i]%j == 0)
  20. {
  21. return 0;
  22. }
  23. }
  24. }
  25. if(primszam == 1)
  26. return 1;
  27. else
  28. return 0;
  29. }
  30.  
  31. int main()
  32. {
  33. int i, db;
  34. char sor[10000];
  35. int szamtomb[1000];
  36. char *p;
  37.  
  38. while(1){
  39. gets(sor);
  40.  
  41. p = strtok(sor," \n");
  42. db = atoi(p);
  43.  
  44. if(db==0) break;
  45.  
  46. for(i=0;i<db;i++)
  47. {
  48. p = strtok(NULL, " \n");
  49. szamtomb[i]=atoi(p);
  50. }
  51.  
  52. printf(prime(szamtomb, db)==1 ? "YES\n" : "NO\n");
  53. }
  54.  
  55.  
  56.  
  57. return EXIT_SUCCESS;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment