Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- long long silnia (int n){
- statistic int luiczba_wywolan=0;//zmienna statyczna
- liczba_wywolan++;
- cout<<"wywolanie nr"<<liczba_wywolan<<", n="<<n<<endl;
- if(n==0)
- return 1;
- if(n>0)
- return n*silnia(n-1);//wywolanie rekurencyjne, funkcja wywoluje sama siebie
- return -1
- }
- int main(){
- int n; long long s;
- cout<<"podaj n";
- cin>>n;
- s=silnia(n);
- if(s>0)
- cout<<"silnia("<<n<<")="<<s;
- esle
- cout<<"niepoprawna wartosc argumentu n";
- cout<<endl;
- }
- system("PAUSE");
- return 1;
- }
- //0!=1
- //n!=n(n-1)!
- //dla n>0
- //s(5)-5*s(4)-4*s(3)-3*s(2)-2*s(1)-1*s(0)
- //5*24=120 4*6=24 3*2=6 2*1=2 1*1=1
Advertisement
Add Comment
Please, Sign In to add comment