Advertisement
MikecIT

Vezba 10 - Zad. 2

Nov 12th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. double suma(int n, double x);
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     double s, x;
  10.     do{
  11.     printf("\nUnesite n: ");
  12.     scanf("%d", &n);
  13.     }while(n<1);
  14.     printf("\nUnesite x: ");
  15.     scanf("%lf", &x);
  16.     s = suma(n, x);
  17.     printf("\nSuma = %.3f", s);
  18.     return 0;
  19. }
  20.  
  21. double suma(int n, double x)
  22. {
  23.     int i, zbir, znak;
  24.     double s,st;
  25.     s=-x+1;
  26.     znak=1;
  27.     st=x;
  28.     zbir=1;
  29.     for(i=1;i<=n;i++)
  30.     {
  31.         if(i<3) s+=x;
  32.         else
  33.         {
  34.             znak*=-1;
  35.             st*=x;
  36.             zbir+=i-1;
  37.             s+=(i*st*x+znak*zbir)/((i-1)*st+zbir+i);
  38.         }
  39.     }
  40.     return s;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement