Check out example codes for "primtiive calculator in c++". It will help you in understanding the concepts better.

Code Example 1

#include <iostream> #include <vector> #include <algorithm> #include <stdio.h> #include <stdlib.h>  long long f(long long n, vector <long long> arr) {      arr[1]=0;      arr.push_back(n);     long long ans=0, ret=0;      if (n==1)     {         return (0);     }     ans= f(n-1, arr) + 1;       if (n%2==0)     {         ret= f(n/2, arr) + 1;         if (ret<ans)         {             ans=ret;             std::cout<<ans<<'\n';         }     }     if (n%3==0)     {          ret= f(n/3, arr) + 1;         if (ret<ans)         {             ans=ret;             std::cout<<ans<<'\n';         }     }     arr[n]=ans;      return arr[n];     }  int main() {      long long n;     std::cin >> n;     std::vector<long long> arr;     std::cout<<f(n, arr);      return 0; }</textarea>          <div class="answer_source">Source: <a target="_blank" href="https://stackoverflow.com/questions/50903024/dynamic-programming-primitive-calculator">stackoverflow.com</a></div>         <br/>

Learn ReactJs, React Native from akashmittal.com