Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int Faktorijel(int);
- int Suma(int);
- int main() {
- int n;
- do {
- cout << "Unesite prirodan broj n: ";
- cin >> n;
- }
- while(n<=0);
- for(int i = 1; i <= n; i++) {
- cout << i << "!";
- if(i<n) cout << " + ";
- else cout << " = " << Suma(n);
- }
- system("pause>0");
- return 0;
- }
- int Faktorijel(int n) {
- if(n<=1)
- return 1;
- return n*Faktorijel(n-1);
- }
- int Suma(int n) {
- int suma = 0;
- for(int i = 1; i <= n; i++) {
- suma += Faktorijel(i);
- }
- return suma;
- }
Advertisement
Add Comment
Please, Sign In to add comment