IvoSilva

[PROG1] Ficha 5 | Exercício 2

Nov 17th, 2011
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. float Q(int n)
  3. {
  4.     float i , res = 0 ;
  5.     for (i = 1 ; i <= n ; i++) res += 1 / (i * i) ;
  6.     return (res) ;
  7. }
  8. float A(int n)
  9. {
  10.     float res , prod1 , prod2 ;
  11.     int i , j ;
  12.     for (res = 0 , i = 1 ; i <= n ; i++)
  13.     {
  14.         for (j = 1 , prod1 = -1 ; j <= i ; j++) prod1 *= -1 ;
  15.         for (j = 1 , prod2 = 1 ; j <= i ; j++) prod2 *= 2 ;
  16.         res += prod1 * (1 / prod2) ;
  17.     }
  18.     return (res) ;
  19. }
  20. int main()
  21. {
  22.     int n ;
  23.     printf ("Indique o valor de N: ") ;
  24.     scanf ("%d" , &n) ;
  25.     printf ("Q(%d)=%.2f e A(%d)=%.4f\n" , n , Q(n) , n , A(n)) ;
  26.     return 0 ;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment