public class Test { public static void Main() { int n; double x, s=0; Console.Write("n = "); n = int.Parse(Console.ReadLine()); Console.Write("x = "); x = double.Parse(Console.ReadLine()); for (int i=1; i <= n; i++) s = x*x/(2*i); Console.WriteLine("s = {0}", s); Console.ReadKey(); } }
2. using System;
public class Test { public static void Main() { int n, i=0; double x, s=0; Console.Write("n = "); n = int.Parse(Console.ReadLine()); Console.Write("x = "); x = double.Parse(Console.ReadLine()); while (i<n){ i++; s = x*x/(2*i); } Console.WriteLine("s = {0}", s); Console.ReadKey(); } }
3. using System;
public class Test { public static void Main() { int n, i=0; double x, s=0; Console.Write("n = "); n = int.Parse(Console.ReadLine()); Console.Write("x = "); x = double.Parse(Console.ReadLine()); do { i++; s = x*x/(2*i); } while (i<n); Console.WriteLine("s = {0}", s); Console.ReadKey(); } }
Answers & Comments
Verified answer
1.using System;
public class Test
{
public static void Main()
{
int n;
double x, s=0;
Console.Write("n = ");
n = int.Parse(Console.ReadLine());
Console.Write("x = ");
x = double.Parse(Console.ReadLine());
for (int i=1; i <= n; i++) s = x*x/(2*i);
Console.WriteLine("s = {0}", s);
Console.ReadKey();
}
}
2.
using System;
public class Test
{
public static void Main()
{
int n, i=0;
double x, s=0;
Console.Write("n = ");
n = int.Parse(Console.ReadLine());
Console.Write("x = ");
x = double.Parse(Console.ReadLine());
while (i<n){
i++;
s = x*x/(2*i);
}
Console.WriteLine("s = {0}", s);
Console.ReadKey();
}
}
3.
using System;
public class Test
{
public static void Main()
{
int n, i=0;
double x, s=0;
Console.Write("n = ");
n = int.Parse(Console.ReadLine());
Console.Write("x = ");
x = double.Parse(Console.ReadLine());
do {
i++;
s = x*x/(2*i);
}
while (i<n);
Console.WriteLine("s = {0}", s);
Console.ReadKey();
}
}
Пример:
n = 5
x = 1.2
s = 0.144