program calklin;
uses
crt;
var
a, b, x: real;
begin
textcolor(red);
gotoxy(10, 5);
write('Вас приветствует калькулятор решать линейные уравнения');
gotoxy(10, 6);
write('Введите а=');
readln(a);
gotoxy(10, 7);
write('Введите b=');
readln(b);
gotoxy(10, 8);
if a = 0
then
begin
gotoxy(10, 9);
textcolor(red);
writeln('Нет корней')
end
else
begin
if a <> 0
then
begin
gotoxy(10, 10);
textcolor(red);
x := (-b / a);
writeln('Уравнение имеет корень и он равен: x =', x, '');
end;
end;
end.
package testStudentCode;
//import java.util.Arrays;
import java.util.Scanner;
public class TestStudentCode {
public static void main(String[] args) {
/* This reads the input provided by user
* using keyboard
*/
Scanner scan = new Scanner(System.in);
System.out.print("a = ?");
// This method reads the number provided using keyboard
double a = scan.nextDouble();
System.out.print("b = ?");
double b = scan.nextDouble();
// Closing Scanner after the use
scan.close();
System.out.println(a + "x + (" + b + ") = 0");
if (a == 0) {
System.out.println("a = 0");
} else {
double x = - b / a;
System.out.println("x = " + x);
}
}
}
Объяснение:
как то так
var a:array[1..n] of integer;
s,p,i:integer;
begin
Randomize;
for i:=1 to n do begin
a[i]:=random(51);
write(a[i],' ');
end;
writeln;
s:=0; p:=1;
for i:=1 to n do
if a[i] mod 10 = 5 then begin s:=s+a[i]; p:=p*a[i]; end;
writeln('s = ',s,' p = ',p);
end.
Пример (для n=10):
18 43 5 30 46 39 21 26 19 25
s = 30 p = 125