class Program { public static void Main() { double a, an = 1, s = 1; int n; Console.Write("a = "); a = double.Parse(Console.ReadLine()); Console.Write("n = "); n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++) { an = an*a; s += an; } Console.WriteLine("s = {0}", s); Console.ReadKey(); } }
class Program { public static void Main() { Console.Write("a = "); var a = double.Parse(Console.ReadLine()); Console.Write("n = "); var n = int.Parse(Console.ReadLine());
var s = 0.0; for (var i = 0; i <= n; i++) s += Math.Pow(a, i);
class Program
{
public static void Main()
{
double a, an = 1, s = 1;
int n;
Console.Write("a = ");
a = double.Parse(Console.ReadLine());
Console.Write("n = ");
n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
an = an*a;
s += an;
}
Console.WriteLine("s = {0}", s);
Console.ReadKey();
}
}
Пример:
a = 2
n = 5
s = 63
class Program
{
public static void Main()
{
Console.Write("a = ");
var a = double.Parse(Console.ReadLine());
Console.Write("n = ");
var n = int.Parse(Console.ReadLine());
var s = 0.0;
for (var i = 0; i <= n; i++)
s += Math.Pow(a, i);
Console.WriteLine($"s = {s}");
Console.ReadKey();
}
}