Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*za uneseni prirodni broj n izračunati sumu:
- S=1!/3^2+2!/5^2+ ... + n!/(2n+1)^2
- Upotrijebite funkciju:
- float suma (int);
- int faktorijel(int);*/
- #include<iostream>
- #include<cmath>
- using namespace std;
- float suma(int);
- int faktorijel(int);
- void main(){
- int n;
- do{
- cout << "Unesi n: ";
- cin >> n;
- } while (n <= 0);
- cout << "Suma: " << suma(n) << endl;
- system("pause");
- }
- float suma(int n){
- float sum = 0;
- int fakt = faktorijel(n);
- for (int i = 1; i <= n; i++){
- sum += fakt / pow((2 * i) + 1, 2.0);
- }
- return sum;
- }
- int faktorijel(int n){
- int fakt = 1;
- for (int i = 1; i <= n; i++){
- fakt *= i;
- }
- return fakt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement