Given the first 2 terms of Geometric Series tell the nth term of the series. Ex. floor(2.3) =2 and floor(-2.3) = -3.
Input:
First line contains an integer, the number of test cases 'T'. Each test case in its first line should contain two positive integer a and b (First 2 terms of GP). In the second line of every test case it contains of an integer N.
First line contains an integer, the number of test cases 'T'. Each test case in its first line should contain two positive integer a and b (First 2 terms of GP). In the second line of every test case it contains of an integer N.
Output:
In each seperate line print the Nth term of the Geometric Progression. Print the floor of the answer.
Constraints:
1<=T<=30
-100<=a<=100
-100<=b<=100
1 <= N <= 5
Example:
Input:
2
2 3
1
1 2
2
Output:
2
2
2
2
Your Code
#include<iostream>
using namespace std;
#include<math.h>
int main()
{
int t;
cin>>t;
while(t--)
{
int a, b;
cin>>a>>b;
int n;
cin>>n;
float r= (float)b/a;
//cout<<r<<endl;
//cout<<r*a;
float t=pow(r,n-1)*a;
int temp=t;
cout<<temp<<endl;
}
}