Requested Evaluation by Experts

Hi all!

I, as a beginner tried to compile a program which calculates the Geometric Progression as per the given parameters.

Now the deal is I got it far too complex in order to work out rational forms. So anybody can help me to frame a simpler function to process even rational forms under this equation


Term = First Term * Common Ratio^nth Term-1
or an= a*rn-1


Please reply to this thread if you want my code first...


Thanks!
Last edited on
That's a recursive definition. You can either implement that recusively (which more directly matches your definition) or iteratively.

You haven't said what the minimum n is and what a is at that value.
"n" is a natural number which is "Number of terms" and "nth term" in this example.

"a" is the first term which is any real number. It may be an integer, decimal or in rational (p/q) form, or more commonly, fractional form, and so the "r".

The deal is my function is quite - a lot complex. That's why I need something simpler so that it can be easier to learn and remember.

And I am sorry as I really don't know what you meant by recursive or iteratively.

:|
Yes, but for any recursive definition like this, there is a minimum n. How else will you know where to begin?
"n" is a natural number, obviously minimum is one...

btw, have a look on my code :-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void Term(double na, double da, double nr, double dr, int no)
{
	if((da != 1) || (dr != 1))
	{
		double a = (na * pow(nr,no));//For GCD
		double b = (da * pow(dr,no));

		if((da * pow(dr,no))/GCD(a,b) != 1)
			cout << (na * pow(nr,no))/GCD(a,b) << "/" << (da * pow(dr,no))/GCD(a,b);//p/q form when q!=0
		else
			cout << (na * pow(nr,no))/GCD(a,b);//p when q=1
	}
	
	if((da == 1) && (dr == 1))
	{
		cout << (na * pow(nr,no));
	}
	if((da == 0) || (dr == 0))
	{
		cout << "ERROR!";
	}
}


na and da are numerator and denominator part of a and likewise, nr and dr are of r.
no is related to another loop.
Last edited on
Topic archived. No new replies allowed.