moranguinho

ex3ER3

Apr 10th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. /*3) Faça um programa que mostre o resultado da seguinte soma, sendo n o valor
  2. informado pelo usuário :
  3. Soma = 1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n*/
  4. #include <stdio.h>
  5. int main(void)
  6. {
  7. int i, n, qtd=0;
  8. float soma=0;
  9.  
  10. printf("Informe um valor: ");
  11. scanf("%d", &n);
  12.  
  13. for(i=1;i<=n;i++)
  14. {
  15. soma = soma + 1.0/i ;
  16. qtd++;
  17. }
  18. printf("soma: %.2f", soma);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment