
Как в Паскале определить простое число или нет? Желательно программу как можно проще. Заранее
спасибо

Ответы на вопрос

var
n,i,j,s :integer;
begin
Write('введите число');
Readln(n);
for i:=1 to n
do begin
s:=0;
for j:=1 to i div 2 do begin
if i mod j=0 then inc(s);end;
if s=1 then Writeln(i);
end;end.
П.С. программа находит все простые числа до заданного тобой числа



How to Determine Prime Numbers in Pascal
To determine whether a number is prime in Pascal, you can use a simple algorithm that checks for divisibility. Here's a basic program to achieve this:
```pascal program PrimeNumberCheck; var num, i: integer; isPrime: boolean; begin writeln('Enter a number: '); readln(num); isPrime := true; for i := 2 to num div 2 do begin if (num mod i) = 0 then begin isPrime := false; break; end; end; if isPrime then writeln(num, ' is a prime number') else writeln(num, ' is not a prime number'); end. ```
In this program: 1. We prompt the user to enter a number. 2. We initialize a boolean variable `isPrime` to true. 3. We then loop through all numbers from 2 to half of the input number, checking for divisibility. If the number is divisible by any of these numbers, it's not prime. 4. If the number is found to be divisible, we set `isPrime` to false and break out of the loop. 5. Finally, we output whether the number is prime or not based on the value of `isPrime`.
This simple program efficiently determines whether a number is prime or not in Pascal.


Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili