limun11

Untitled

Sep 20th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. float suma(int);
  6. int faktorijel(int);
  7.  
  8. int main()
  9. {
  10. int n;
  11. int sum = 0;
  12. cout << "Unesite broj: " << endl;
  13. cin >> n;
  14. cout << "Suma je: " << suma(n) << endl;
  15. system("PAUSE");
  16. return 0;
  17. }
  18.  
  19. float suma(int n)
  20. {
  21. float sum = 0;
  22. for (int i = 1; i <= n; i++)
  23. {
  24. sum = sum +(pow(-1, i-1)* i / faktorijel(i));
  25. }
  26. return sum;
  27. }
  28.  
  29. int faktorijel(int n)
  30. {
  31. int faktor = 1;
  32. {
  33. for (int i = 1; i <= n; i++)
  34. {
  35. faktor = faktor*i;
  36. }
  37. }
  38. return faktor;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment