Dastur
Program L24a; {Sonning bo’luvchilari. 2 -usul }
uses Crt;
var
n, d : integer;
begin
write('Butun sonni kiriting '); readln(n);
writeln(n, ‘sonining bo’luvchilari’);
d := 1;
while d*d < n do
begin
if n mod d=0 then write(d, ' ', n div d, ' ');
d := d + 1
end;
if d*d = n then write(d); writeln
end.
Topshiriqlar:
N natural son. Shu sonni bo’luvchilarini chiqaruvchi dastur tuzing? Masalan: 30 ning bo’luvchilari 1,2,3,5,6,10,15,3
Yechim:
let n = 30;
let bolens = [];
for (let i = 1; i <= n; i++) {
if (n % i == 0) {
bolens.push(i);
}
}
console.log(bolens);
Natijasi:
Do'stlaringiz bilan baham: |