Guest User

Untitled

a guest
Jun 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define TAM 100
  4.  
  5. struct tVetorInt {
  6.  
  7. int vet[TAM];
  8. int n;
  9. };
  10.  
  11. typedef struct tVetorInt tVetorInt;
  12.  
  13.  
  14. int ehprimo (int a, tVetorInt v) {
  15.  
  16. int i;
  17.  
  18. for(i=0; v.vet[i]<=pow(a,0.5); i++) {
  19.  
  20. if (a%v.vet[i]==0) return 0;
  21.  
  22. }
  23.  
  24. return 1;
  25.  
  26. }
  27.  
  28.  
  29. tVetorInt primos (void) {
  30.  
  31. int a;
  32.  
  33. tVetorInt v;
  34.  
  35. v.vet[0] = 2;
  36. v.n = 0;
  37.  
  38. for (a=2; v.n<TAM; a++) {
  39.  
  40. if (ehprimo (a,v)) {
  41.  
  42. v.vet[(v.n)] = a;
  43. v.n++;
  44.  
  45. }
  46.  
  47. }
  48.  
  49. return v;
  50. }
  51.  
  52. void imprimeVetor (tVetorInt v) {
  53.  
  54. int i;
  55.  
  56. for (i=0; i<v.n; i++) {
  57.  
  58. printf("%d ", v.vet[i]);
  59. }
  60.  
  61. printf("\n");
  62.  
  63. }
  64.  
  65.  
  66. main () {
  67.  
  68. tVetorInt v;
  69.  
  70. v = primos();
  71.  
  72. imprimeVetor(v);
  73.  
  74. }
Add Comment
Please, Sign In to add comment