Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define TAM 100
- struct tVetorInt {
- int vet[TAM];
- int n;
- };
- typedef struct tVetorInt tVetorInt;
- int ehprimo (int a, tVetorInt v) {
- int i;
- for(i=0; v.vet[i]<=pow(a,0.5); i++) {
- if (a%v.vet[i]==0) return 0;
- }
- return 1;
- }
- tVetorInt primos (void) {
- int a;
- tVetorInt v;
- v.vet[0] = 2;
- v.n = 0;
- for (a=2; v.n<TAM; a++) {
- if (ehprimo (a,v)) {
- v.vet[(v.n)] = a;
- v.n++;
- }
- }
- return v;
- }
- void imprimeVetor (tVetorInt v) {
- int i;
- for (i=0; i<v.n; i++) {
- printf("%d ", v.vet[i]);
- }
- printf("\n");
- }
- main () {
- tVetorInt v;
- v = primos();
- imprimeVetor(v);
- }
Add Comment
Please, Sign In to add comment