1. program pr1; uses crt; var n,k,i,t:integer; begin clrscr; write('Введите целое число n='); readln (n); for i:=2 to n do begin t:=0; for k:=2 to n do if i mod k=0 then t:=t+1; if t=1 then write(i:3); end; readln; end.
2.
Program pr2; Var a, b: Integer;
Function NOD(a, b: Integer): Integer; Var tmp, r: Integer; Begin If b > a Then Begin tmp := a; a := b; b := tmp; End; tmp := a; While tmp > 0 Do Begin Result := tmp; tmp := tmp - b; End; End;
program pr1;
uses crt;
var n,k,i,t:integer;
begin
clrscr;
write('Введите целое число n=');
readln (n);
for i:=2 to n do begin
t:=0;
for k:=2 to n do
if i mod k=0 then t:=t+1;
if t=1 then write(i:3);
end;
readln;
end.
2.
Program pr2;
Var a, b: Integer;
Function NOD(a, b: Integer): Integer;
Var tmp, r: Integer;
Begin
If b > a Then
Begin
tmp := a;
a := b;
b := tmp;
End;
tmp := a;
While tmp > 0 Do
Begin
Result := tmp;
tmp := tmp - b;
End;
End;
Begin
Write('a = ');
ReadLn(a);
Write('b = ');
ReadLn(b);
Write('НОД: ', NOD(a, b));
ReadLn;
End.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double a, b, c, x1, x2, d;
do{
cout << "Input a: ";
cin >> a;
if (a == 0) {
cout << "Error! a = 0! This isn't a square equation! Try again" << endl;
}
} while (a == 0);
cout << "Input b: ";
cin >> b;
cout << "Input c: ";
cin >> c;
d = b * b - 4. * a * c;
if (d < 0) {
cout << "No roots";
return 1;
}
else if (d == 0) {
cout << "x = " << -b / 2. / a;
return 2;
}
else {
cout << "x1 = " << (-b + sqrt(d)) / 2. / a << ", x2 = " << (-b - sqrt(d)) / 2. / a;
return 0;
}
}