Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cmath>
- using namespace std;
- float suma(int);
- int faktorijel(int);
- int main()
- {
- int n;
- int sum = 0;
- cout << "Unesite broj: " << endl;
- cin >> n;
- cout << "Suma je: " << suma(n) << endl;
- system("PAUSE");
- return 0;
- }
- float suma(int n)
- {
- float sum = 0;
- for (int i = 1; i <= n; i++)
- {
- sum = sum +(pow(-1, i-1)* i / faktorijel(i));
- }
- return sum;
- }
- int faktorijel(int n)
- {
- int faktor = 1;
- {
- for (int i = 1; i <= n; i++)
- {
- faktor = faktor*i;
- }
- }
- return faktor;
- }
Advertisement
Add Comment
Please, Sign In to add comment