limun11

Untitled

Sep 19th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int faktor(int);
  5. float suma(int);
  6. float ukupnasuma(int);
  7. int main()
  8. {
  9.  
  10.     int n;
  11.     cout << "Unesite n: " << endl;
  12.     cin >> n;
  13.    
  14.     while (n < 0)
  15.     {
  16.         cout << "Broj koji ste unijeli nije prirodan. Ponovite unos: " << endl;
  17.         cin >> n;
  18.     }
  19.    
  20.     cout << "Suma iznosi: " << ukupnasuma(n) << endl;
  21.  
  22.     system("PAUSE");
  23.     return 0;
  24. }
  25.  
  26. int faktor(int n)
  27. {
  28.     int faktorijel = 1;
  29.     for (int i = 1; i <=n; i++)
  30.     {
  31.         faktorijel = faktorijel*i;
  32.     }
  33.     return faktorijel;
  34. }
  35.  
  36. float suma(int n)
  37. {
  38.     float sum = 0;
  39.     for (int i = 2; i <= n; i++)
  40.     {
  41.         sum = sum + (1 /2 + 1/(float) i);
  42.     }
  43.     return sum;
  44. }
  45.  
  46. float ukupnasuma(int n)
  47. {
  48.     float usum = 0;
  49.    
  50.             usum = usum + faktor(n) / suma(n);
  51.        
  52.     return usum;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment