#include<bits/stdc++.h>
using namespace std;
int counter(int n)
{
if(n == 0)
return 1;
else if(n == 1)
return 0;
else if(n == 2)
return 1;
return (n-1)*(counter(n-1) + counter(n-2));
}
int main()
{
int n;
cout << "Enter A Number :: ";
cin >> n;
int Derangement_Number = counter(n);
cout << "\n" << n << " Element Derangement Number is :: " << Derangement_Number << "\n";
return 0;
}
Comments
Post a Comment