Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Si realizzi un programma che legga un intero N da tastiera,
- e stampi a video il risultato della seguente sommatoria:
- (Vedere slide esercizio n°9) */
- #include <stdio.h>
- int main() {
- int i, n, esp;
- float som;
- do {
- printf ("Inserire un valore positivo a cui deve tendere la sommatoria: ");
- scanf ("%d", &n);
- som=0;
- for (i=0; i<=n; i++) {
- if (i%2 == 0)
- esp = 1;
- else
- esp = -1;
- som = som + (float) esp*4/(2*i + 1);
- }
- if (n>=0)
- printf ("\nIl risultato e': %g\n", som);
- } while (n>=0);
- system ("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment