Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int eprimo(int x)
- {
- int y = 2;
- while (x > y)
- {
- if (x % y == 0)
- {
- return 0;
- }
- y++;
- }
- return 1;
- }
- int fatorial(int x)
- {
- int resultado;
- if (x == 1)
- {
- return 1;
- }
- else{
- resultado = x * fatorial(x - 1);
- }
- return resultado;
- }
- int proxprimo(int z)
- {
- if(eprimo(z) == 0)
- {
- proxprimo(z + 1);
- }
- else if(eprimo(z) == 1)
- {
- return z;
- }
- }
- int main()
- {
- int termo = 1, n = 0, prox1 = 0;
- double resposta = 0.0, prox = 0.0, fat = 0.0, termo1 = 0.0;
- scanf("%d", &n);
- for( ; termo <= n; termo++)
- {
- fat = fatorial(termo); prox = proxprimo(termo); prox1 = prox; termo1 = termo;
- if (termo == 1)
- {
- resposta += 1.00;
- printf("1!/1");
- }
- else if(eprimo(termo) != 0)
- {
- resposta += fat / termo1;
- printf(" + %d!/%d", termo, prox1);
- }
- else if(eprimo(termo) == 0)
- {
- resposta += fat / prox;
- printf(" + %d!/%d", termo, prox1);
- }
- }
- printf("\n%.2lf", resposta);
- return 0;
- }
- /*
- fat = fatorial(termo); prox = proxprimo(termo); prox1 = prox;
- resposta += fat / prox;
- printf(" + %d!/%d", termo, prox1);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement