Advertisement
MikecIT

Vezba 10 - Zad. 1

Nov 12th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 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 = %.4f", s);
  18.     return 0;
  19. }
  20.  
  21. double suma(int n, double x)
  22. {
  23.     int i, zbir;
  24.     double s,st;
  25.     s=1;
  26.     st=1;
  27.     zbir=0;
  28.     for(i=1;i<n;i++)
  29.     {
  30.         st*=x;
  31.         zbir+=i;
  32.         s+=st/(st + zbir);
  33.     }
  34.     return s;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement