На Паскале:
Объяснение:
var a, b, c, d, x : real;
begin
Write('Введите значение A: '); ReadLn(a);
Write('Введите значение B: '); ReadLn(b);
Write('Введите значение C: '); ReadLn(c);
WriteLn;
d := sqr(b) - 4 * a * c;
if (a = 0) and (b = 0) and (c = 0) then
begin
WriteLn('X - любое число.');
end else if (a = 0) and (b = 0) then
begin
WriteLn('Заданное уравнение не имеет решений!');
end else if (a = 0) then
begin
WriteLn('Старший коэффициент не может равняться нулю.');
WriteLn('В этом случае уравнение преобразуется в линейное.');
x := (-c) / b;
WriteLn('X = ',x:2:2);
end else if ((a <> 0) and (b <> 0)) then
begin
if (d > 0) then
begin
WriteLn('D = ',d:2:2);
WriteLn('Корень D = ',sqrt(d):2:2);
x := ((-b) + sqrt(d)) / (2 * a);
WriteLn('X1 = ',x:2:2);
x := ((-b) - sqrt(d)) / (2 * a);
WriteLn('X2 = ',x:2:2);
end else if (d < 0) then
begin
WriteLn('D = ',d:2:2);
WriteLn('D < 0, поэтому уравнение не имеет решений!');
end else if (d = 0) then
begin
x := (-b) / (2 * a);
WriteLn('D = ',d:2:2);
WriteLn('X = ',x:2:2);
end;
end;
end.
Вводить только чётное количество цифр, иначе будет "Error". Табуляцию сам расставь.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int x;
int x2;
int counter = 0;
cout << "Enter x: ";
cin >> x;
x2 = x;
while(x2 % 10)
{
x2 /= 10;
counter++;
}
if(counter % 2 == 0)
{
int sum1 = 0, sum2 = 0;
for(int i = counter; i > counter / 2; i--)
{
sum1 += x % 10;
x /= 10;
}
while(x % 10)
{
sum2 += x % 10;
x /= 10;
}
if(sum2 > sum1)
{
cout << "The first part" << endl;
}
else if(sum2 < sum1)
{
cout << "The second part" << endl;
}
else
cout << "They are equal" << endl;
}
else
cout << "Error" << endl;
return 0;
}