Из программы сделать функцию - C#
Формулировка задачи:
{
Console.WriteLine("Введите A:");
int A = int.Parse(Console.ReadLine());
Console.WriteLine("Введите B:");
int B = int.Parse(Console.ReadLine());
Console.WriteLine("Введите C:");
int C = int.Parse(Console.ReadLine());
int D = B * B - 4 * A * C;
if (D >= 0)
Console.WriteLine("Вещественные корни: D="+D);
else
Console.WriteLine("Комплексные корни: D="+D);
Console.ReadKey(true);
}Решение задачи: «Из программы сделать функцию»
textual
Листинг программы
using System;
namespace Marialashina197
{
class Program
{
private String MarialashinaMathod() {
Console.Write("Введите A:"); int A = int.Parse(Console.ReadLine());
Console.Write("Введите B:"); int B = int.Parse(Console.ReadLine());
Console.Write("Введите C:"); int C = int.Parse(Console.ReadLine());
int D = (int)Math.Pow(B, 2.0) - 4 * A * C;
if (D >= 0)
return "Вещественные корни: D = " + D;
else
return "Комплексные корни: D = " + D;
}
static void Main(string[] args)
{
Console.WriteLine(new Program().MarialashinaMathod());
Console.ReadLine();
}
}
}