Advertisement
Guest User

Untitled

a guest
May 24th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. /*za uneseni prirodni broj n izračunati sumu:
  2. S=1!/3^2+2!/5^2+ ... + n!/(2n+1)^2
  3. Upotrijebite funkciju:
  4. float suma (int);
  5. int faktorijel(int);*/
  6. #include<iostream>
  7. #include<cmath>
  8. using namespace std;
  9.  
  10. float suma(int);
  11. int faktorijel(int);
  12. void main(){
  13. int n;
  14. do{
  15. cout << "Unesi n: ";
  16. cin >> n;
  17. } while (n <= 0);
  18. cout << "Suma: " << suma(n) << endl;
  19. system("pause");
  20. }
  21. float suma(int n){
  22. float sum = 0;
  23. int fakt = faktorijel(n);
  24. for (int i = 1; i <= n; i++){
  25. sum += fakt / pow((2 * i) + 1, 2.0);
  26. }
  27. return sum;
  28. }
  29. int faktorijel(int n){
  30. int fakt = 1;
  31. for (int i = 1; i <= n; i++){
  32. fakt *= i;
  33. }
  34. return fakt;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement