September 2018 2 49 Report
Co w tym programie robi zmienna Licz ? Zakładam, że liczy obiegi pętli, ale czy może ktoś jasno wytłumaczyć krok po kroku to :

If ((i mod j) = 0) Then Licz:=Licz+1; Czemu + 1 ?
IF Licz = 2 then begin ?? Dlaczego akurat 2, a nie np. 3 ?

Proszę o jasne wytłumaczenie, daje 40 pkt !!

Program Liczby_pierwsze;
Uses Crt;
Var N, K : Integer;
i, j : Integer;
Licz : Integer;
Begin
Repeat
Clrscr;
Writeln('Podaj liczbę naturalną (N > 1)');
Write('n = ');
Readln(N);
Until (N > 1);
K:= 1;
Write('Liczby pierwsze: ');
For i:=1 To N Do Begin
Licz :=0;
For j:=1 To N Do
If ((i mod j) = 0) Then Licz:=Licz+1;
If Licz = 2 Then Begin
Write(i,' ');
K:=K+1
End;
End;
Writeln;
Writeln('Liczba liczb pierwszych = ',k);
Repeat Until Keypressed;
End.
More Questions From This User See All

Recommend Questions



Life Enjoy

" Life is not a problem to be solved but a reality to be experienced! "

Get in touch

Social

© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.