Monday, 26 March 2018

Recursion- DSA

By: Gulfam Tahir
Section : E2


                   Permutation Program through Recursive Call

#include<iostream>
using namespace std;
int punction(int,int);
int fac(int);
int fac(int n){
                if(n<=1){
                                return 1;           //base case
                }else{
                                return n*fac(n-1);     //recrssive case
                }
}


int punction(int k,int r){


                if(k<=1){
                                return 1;               //base case
                }
                else                          
                 {
                                return (k-r)*fac(k-r-1);     //recurssive case
                 }
}


int main(){
                cout<<"\n\n******************** Permutation *********************"<<endl;
                int n,r;
                                cout<<"\n\nEnter n"<<endl;
                cin>>n;
                cout<<"enter value of r"<<endl;
                cin>>r;

               
                int j=fac(n)/punction(n,r);
                cout<<"permutation of "<<n<<"P"<<r<<" "<<"is"<<" "<<j;
}

0 comments:

Post a Comment