-
Notifications
You must be signed in to change notification settings - Fork 0
/
primosNfatorial.c
76 lines (39 loc) · 940 Bytes
/
primosNfatorial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<stdio.h>
int verificaPrimo(long int num)
{
int i;
int conta=0;
for(i=1; i<=num; i++) {
if(num%i==0) conta++;
}
if(conta==2) {
return 1; // retorna um se primo
} else {
return 0; // retorna zero se não é primo
}
}
int main() {
long int numeroN, fatorialN;
long int aux, leituraValida=0;
//leitura do número N
while (leituraValida == 0) {
scanf("%ld", &numeroN);
if (numeroN >= 0) {
leituraValida=1;
}
}
for(fatorialN = 1; numeroN > 1; numeroN = numeroN - 1) {
fatorialN = fatorialN * numeroN;
}
if (fatorialN==2) {
printf ("NENHUM PRIMO");
}
else {
for(aux=0; aux<=fatorialN; aux++) {
if(verificaPrimo(aux)==1) {
printf(" %ld ", aux);
}
}
}
return 0;
}