title: Amazon online assessment coding question to find nth Geometric Progression
body: <p>Given the 2nd and 3rd term of a Geometric Progression. Find the nth term of it and round it off up to 3 decimal places.</p>
  
  <p>we have to complete the following function:</p>
  
  <pre><code>char* nthTerm(double input1, double input2, int input3) {
      //your code here
  }
  </code></pre>
  
  <pre><code>input1 = 2nd term and input2 = 3rd term and both are between -2 to 2.
  input3 = nth term to find and can be up to 100.
  </code></pre>
  
  <p>I was unable to convert the result from double to an array of char in the time limits. The test was on <a href="http:////https://mettl.com/" rel="nofollow noreferrer">Mettl</a> platform and I think I was unable to use to_string(), stringstream, etc. Although pow() function working fine.</p>
  
  <pre><code>e.g input1 = 1, input2 = 2, input3 = 4
    output = 4.0
  </code></pre>
  
  <p>Please, someone, help on how to solve this problem.</p>
  
  <p>My approach but getting compilation error and wrong verdicts:</p>
  
  <pre><code>    double r = input2/input1;
      double a = input1/r;
      double ans = a * (double)pow(r, (double)(input3-1));
      char *result = new char[1000];
      // from here i tried so many thing like i used to_string, 
      // setprecision, maps, etc. But getting errors only.
  
  </code></pre>