Ввести числа через Enter.
Объяснение:
Dev C++
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale>
int main(int argc, char** argv) {
int a, b, c, y, r, h;
setlocale(LC_ALL, "rus");
double x1, x2, d;
printf("a * x^2 + b * x + c = 0\n");
printf("Ââåäèòå a = ");
scanf("%d", &a);
printf("Ââåäèòå b = ");
scanf("%d", &b);
printf("Ââåäèòå c = ");
scanf("%d", &c);
d = pow(b,2) - 4 * a * c;
printf("D = %f\n", d);
y = sqrt(d);
h = -b;
r = 2 * a;
if (d > 0){
x1 = ((h + y) / r);
x2 = ((h - y) / r);
printf("Êîðíè : \nx1 = %f,\nx2 = %f", x1, x2);
}
if (d == 0){
x1 = (h / r);
x1 = x2;
if (d < 0) printf("False");
return 0;
Pascal ABC - среда разработки;
var
a, b, c, d: real;
begin
read(a, b, c);
d := (power(b, 2) - 4 * a * c);
if d > 0 then
writeln('x1 = ', (-b + sqrt(d)) / (2 * a));
writeln('x2 = ', (-b - sqrt(d)) / (2 * a));
halt
end;
if d = 0 then writeln('x = ', (-b) / (2 * a))
else writeln('Корней нет')
end.
Ввести числа через Enter.
Объяснение:
Dev C++
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale>
int main(int argc, char** argv) {
int a, b, c, y, r, h;
setlocale(LC_ALL, "rus");
double x1, x2, d;
printf("a * x^2 + b * x + c = 0\n");
printf("Ââåäèòå a = ");
scanf("%d", &a);
printf("Ââåäèòå b = ");
scanf("%d", &b);
printf("Ââåäèòå c = ");
scanf("%d", &c);
d = pow(b,2) - 4 * a * c;
printf("D = %f\n", d);
y = sqrt(d);
h = -b;
r = 2 * a;
if (d > 0){
x1 = ((h + y) / r);
x2 = ((h - y) / r);
printf("Êîðíè : \nx1 = %f,\nx2 = %f", x1, x2);
}
if (d == 0){
x1 = (h / r);
x1 = x2;
printf("Êîðíè : \nx1 = %f,\nx2 = %f", x1, x2);
}
if (d < 0) printf("False");
return 0;
}
Pascal ABC - среда разработки;
var
a, b, c, d: real;
begin
read(a, b, c);
d := (power(b, 2) - 4 * a * c);
if d > 0 then
begin
writeln('x1 = ', (-b + sqrt(d)) / (2 * a));
writeln('x2 = ', (-b - sqrt(d)) / (2 * a));
halt
end;
if d = 0 then writeln('x = ', (-b) / (2 * a))
else writeln('Корней нет')
end.