(pascal.)
program ; var a,b,x1,x2,x3: real; beginwriteln('введите коэффициент a'); readln(a); writeln('введите коэффициен b'); readln(b);
x1: =0;
if (b> 0) and (a> 0) then writeln('корни ур-я равны ',x1) elsex2: =sqrt(-b/a); x3: =-sqrt(-b/a); writeln('корни ур-я равны ',x1,x2,x3);
end.
Решение
Pascal- Python
var
a: array[1..1000] of real;
n, i, mi, ma: integer;
max, min: real;
begin
write('Введите N: ');
readln(n);
for i := 1 to n do
begin
write('Введите ', i, ' элемент: ');
readln(a[i]);
if i = 1 then begin max := a[i]; min := a[i]; ma := i; mi := i; end;
if min > a[i] then begin min := a[i]; mi := i; end;
if max < a[i] then begin max := a[i]; ma := i; end;
end;
writeln;
writeln('Ваш массив: ');
for i := 1 to n do writeln(i, ') ', a[i], ' ');
writeln;
writeln('Массив после замены Max на Min: ');
a[mi] := a[ma] + a[mi];
a[ma] := a[mi] - a[ma];
a[mi] := a[mi] - a[ma];
for i := 1 to n do writeln(i, ') ', a[i], ' ');
end.
1)
using system;
class program {
static void main() {
int num = 16;
bool ispow2 = true;
while (num > 1){
if (num % 2 == 0){
num /= 2;
} else {
ispow2 = false;
break;
}
}
if (ispow2)
console.writeline("является");
else
console.writeline("не является");
}
}
2)
using system;
class program {
static random rnd = new random();
static void main() {
int min = 1;
int max = 100;
int numofattempts = 8;
int x = rnd.next(min, max);
bool iswin = false;
console.writeline("игра \"больше-меньше\"");
console.write("задайте число попыток: ");
numofattempts = convert.toint32(console.;
console.writeline("отгадайте число от {0} до {1}", min, max);
console.writeline("попытки: {0}\n", numofattempts);
int input;
do {
console.write("введите число: ");
input = convert.toint32(console.;
numofattempts--;
if (input > x)
console.writeline("x < {0} [попытки: {1}]", input, numofattempts);
if (input < x)
console.writeline("x > {0} [попытки: {1}]", input, numofattempts);
if (input == x){
iswin = true;
break;
}
} while (numofattempts > 0);
if (iswin){
console.writeline("\nпобеда! ");
} else {
console.writeline("\nпроигрыш! загаданное число: {0}", x);
}
}
}
Поделитесь своими знаниями, ответьте на вопрос:
Написать програму решения уравнения ах^3 + вх = 0 для произвольных а, в
vara, b, x2, x3 : real; begin writeln('введите коэффициент a'); readln (a); writeln('введите коэффициен b'); readln (b); if b = 0 then begin if a = 0 then writeln ('x - любое число') else writeln('корни ур-я равны: 0') end else if (a = 0) or (- b / a < = 0) then writeln ('корни ур-я равны: 0') else begin x2 : = sqrt(-b / a); x3 : = -sqrt(-b / a); writeln('корни ур-я равны 0, ', x2,' ',x3); end; readln; end.