Найти корни уравнения - C# (186283)
Формулировка задачи:
Здравствуйте.
Возникла проблема при решении уравнения, а, именно, нужно, чтобы Y выдавал только целые числа.
Вот код:
Заранее благодарен.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace korniUr
{
class Program
{
static void Main(string[] args)
{
int x = -100;
int y;
string ch;
double[] array = new double[200];
for (int i = 0; i < 200; i++)
{
array[i] = x;
y = (int)Math.Sqrt((x + 1) * (x + 7) * (x + 8));
ch = y.ToString();
if((y > -100) && (y <= 100) && (int.TryParse(ch, out y))) // пытался через TryParse... Не получилось.
{
Console.WriteLine("X = {0} Y = {1}", x , y);
}
x++;
}
Console.ReadKey();
}
}
}Решение задачи: «Найти корни уравнения»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace korniUr
{
class Program
{
static void Main(string[] args)
{
int x = -100;
double y;
string ch;
double[] array = new double[200];
int c;
for (int i = 0; i < 200; i++)
{
array[i] = x;
y = Math.Sqrt((x + 1) * (x + 7) * (x + 8));
ch = y.ToString();
c = (int)y;
if ((y > -100) && (y <= 100) && (int.TryParse(ch, out c)))
{
Console.WriteLine("X = {0} Y = {1}", x , y);
}
x++;
}
Console.ReadKey();
}
}
}