Код программы:
#include <iostream>
#include <locale>
using namespace std;
int main() {
setlocale(LC_ALL, "Russian");
double D, a, b, c, x1, x2;
cout<<"Введите коэффициент a" << endl;
cin >> a;
if (a == 0) {
cout << "Ошибка ввода! Коэффициент a не должен равняться 0" << endl;
return 0;
}
cout << "Введите коэффициент b" << endl;
cin >> b;
cout << "Введите коэффициент c" << endl;
cin >> c;
cout << "\nВаше уравнение: " << a << "x^(2) + " << b << "x + " << c << endl;
D = sqrt(b*b - 4 * a * c);
if (D >= 0) {
if (D == 0) {
x1 = (-b) / (2 * a);
cout << "x1 = " << x1 << endl;
}
else {
x1 = (-b - D) / (2 * a);
x2 = (-b + D) / (2 * a);
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}
}
else
cout << "\nУравнение не имеет корней (D < 0)" << endl;
return 0;
}
Так как язык не указан, приведу пример на SWI-Prolog.
Код:
read_int(Int) :- read(Int), integer(Int).split_int_by_numbers(0, []) :- !.split_int_by_numbers(N, [Number|Ints]) :- Number is mod(N, 10), RestN is div(N, 10), split_int_by_numbers(RestN, Ints).test_to_div(_, []).test_to_div(N, [Number|Ints]) :- mod(N, Number) =:= 0, test_to_div(N, Ints). test(Int) :- split_int_by_numbers(Int, Numbers), test_to_div(Int, Numbers), write(Int), write(" - Yes!"), nl.test(Int) :- write(Int), write(" - No!"), nl.?- read_int(Int), test(Int).
95 * 1024 * 1024 = 97669120 КБ
97669120 ÷ 400 = 244172 с ≈ 67,8 часов