two left
This commit is contained in:
24
labs/lab7_done/Progrssion/GeometricProgression.cs
Normal file
24
labs/lab7_done/Progrssion/GeometricProgression.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
class GeometricProgression : Progression
|
||||
{
|
||||
private int p0;
|
||||
private int q;
|
||||
|
||||
public GeometricProgression(int p0, int q)
|
||||
{
|
||||
this.p0 = p0;
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
public override int GetElement(int k)
|
||||
{
|
||||
return p0 * (int)Math.Pow(q, k - 1);
|
||||
}
|
||||
|
||||
public override int Sum(int n)
|
||||
{
|
||||
if (q == 1) return p0 * n;
|
||||
return p0 * (int)((Math.Pow(q, n) - 1) / (q - 1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user