Saturday, 20 September 2025

RECURSION_4 VIDEO

 #include<iostream>

#include<string>

using namespace std;

void printsub(string ans,string str,int idx=0){

    if(idx==str.length()){

        cout<<ans<<endl;

        return;

    }

    if(ans==""||(str[idx-1]==ans[ans.length()-1])){

          printsub(ans+str[idx],str,idx+1);

    }

    

  

    printsub(ans,str,idx+1);

}

int palindrome(int arr[],int n){

    

    int i=0;

    int j=n-1;

    while(i!=j){

        if(arr[i]==arr[j]){

            i++;

            j--;

        }

        else{

            return -1;

            break;

            

        }

    }

    return 1;

}

int min(int i ,int j){

    if(i<j) return i;

    return j;

}

int hcf(int one,int two){

    int mini=min(one,two);

    int c=1;

    for (int i =2;i<=mini;i++){

        if(one%i==0&&two%i==0){

            

         c=i;

         

        }

    }

    cout<<" common divisor "<<c;

    return 0;

}

void euclid(int a ,int b){

    if(a==0){

cout<<"gcd is "<<b;

        return ;

    }

     euclid(b%a,a);


}

void gcdeuclid(int a,int b){

    if(a<b){

        euclid(a,b);

    }

    else{

        euclid(b,a);

        

    }

}


int main(){

    // printsub("","abc");

    // int arr[]={1,2,3,3,1};

    // int n =sizeof(arr)/sizeof(arr[0]);

    // int flag=palindrome(arr,n);

    // cout<<flag;

    // hcf(4,8);

    gcdeuclid(1000000001,10000);

}

No comments:

Post a Comment

SDE floyd-warshall algorithm

 // User function template for C++ class Solution {   public:     void floydWarshall(vector<vector<int>> &dist) {         //...