Guest User

Untitled

a guest
Apr 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /* Si realizzi un programma che legga un intero N da tastiera,
  2. e stampi a video il risultato della seguente sommatoria:
  3. (Vedere slide esercizio n°9) */
  4.  
  5. #include <stdio.h>
  6.  
  7. int main() {
  8. int i, n, esp;
  9. float som;
  10.  
  11. do {
  12. printf ("Inserire un valore positivo a cui deve tendere la sommatoria: ");
  13. scanf ("%d", &n);
  14.  
  15. som=0;
  16.  
  17. for (i=0; i<=n; i++) {
  18. if (i%2 == 0)
  19. esp = 1;
  20. else
  21. esp = -1;
  22.  
  23. som = som + (float) esp*4/(2*i + 1);
  24. }
  25.  
  26. if (n>=0)
  27. printf ("\nIl risultato e': %g\n", som);
  28. } while (n>=0);
  29.  
  30. system ("pause");
  31. return 0;
  32.  
  33. }
Add Comment
Please, Sign In to add comment