Những câu hỏi liên quan
TKT VN
Xem chi tiết
nguyễn an phát
1 tháng 9 2021 lúc 11:21

program bai_1;
uses crt;
var i,n,j,d,dem:word;
begin
  clrscr;
  repeat
    write('nhap n:');readln(n);
    if (n<=0)or(n>=10000)then writeln('so ban nhap khong hop le, ban hay nhap lai:');
  until (n>0)and(n<10000);
  writeln('cac uoc so la so tu nhien cua ',n,' la:');
  for i:=1 to n do
  if n mod i=0 then write(i,'    ');
  writeln;
  dem:=0;
  for i:=2 to n do
  begin
    d:=0;
    for j:=2 to i div 2 do
    if i mod j=0 then inc(d);
    if (d=0)and(n mod i=0)then inc(dem);
  end;
  if dem>0 then writeln('cac uoc so la so nguyen to cua ',n,' la:');
  begin
    d:=0;
    for j:=2 to i div 2 do
    if i mod j=0 then inc(d);
    if (d=0)and(n mod i=0)then write(i,'    ');
  end;
  if dem=0 then write(0);
  readln;
end.

 

hoàng đá thủ
Xem chi tiết
Nguyễn Lê Phước Thịnh
29 tháng 8 2023 lúc 21:00

uses crt;

var i,n,t,j,kt:integer;

begin

clrscr;

readln(n);

t:=0;

for i:=2 to n do

if n mod i=0 then

begin

kt:=0;

for j:=2 to trunc(sqrt(i)) do

if i mod j=0 then kt:=1;

if kt=0 then t:=t+i;

end;

write(t);

readln;

end.

Lê Minh Thuận
30 tháng 8 2023 lúc 16:38

Dưới đây là một ví dụ về chương trình Pascal để tính tổng các ước số nguyên tố của một số tự nhiên n:

```pascal
program TinhTongUocSoNguyenTo;
var
n, i, j, sum: integer;
isPrime: boolean;
begin
write('Nhap vao so tu nhien n: ');
readln(n);

sum := 0;

for i := 1 to n do
begin
if n mod i = 0 then // Kiểm tra i có là ước số của n không
begin
isPrime := true;

for j := 2 to trunc(sqrt(i)) do // Kiểm tra i có phải là số nguyên tố không begin if i mod j = 0 then begin isPrime := false; break; end; end; if isPrime then // Nếu i là số nguyên tố, cộng vào tổng sum := sum + i; end;

end;

writeln('Tong cac uoc so nguyen to cua ', n, ' la: ', sum);
end.
```

Chương trình trên sẽ yêu cầu bạn nhập vào số tự nhiên n, sau đó tính tổng các ước số nguyên tố của n và hiển thị kết quả.

35.Yến Oanh 8/4
Xem chi tiết
Nguyễn Lê Phước Thịnh
30 tháng 3 2022 lúc 20:22

#include <bits/stdc++.h>

using namespace std;

long long i,n,dem;

int main()

{

cin>>n;

dem=0;

for (i=1; i<=n; i++)

if (n%i==0)

{

cout<<i<<" ";

dem++;

}

cout<<endl;

cout<<dem;

return 0;

}

Trần Thị Mai Ngọc
Xem chi tiết
nguyễn an phát
18 tháng 4 2021 lúc 20:48

program tim_uoc;

uses crt;

var i,n,tong:integer;

begin

clrscr;

write('nhap so n:');readln(n);

i:=1;tong:=0;

writeln('cac uoc cua ',n,' la:');

while i<=n do

if n mod i=0 then

begin

write(i:3);

inc(i);

end;

writeln;

i:=1;writeln('cac uoc chan:');

while i<=n do

begin

if n mod i=0 then 

begin

if i mod 2=0 then write(i:3);

tong:=tong+i;

end;

end;

writeln;

write('tong cac uoc chan:',tong);

readln;

end.

Nguyễn Lê Phước Thịnh
19 tháng 4 2021 lúc 19:17

uses crt;

var n,i,t:integer;

begin

clrscr;

write('Nhap n='); readln(n);

i:=1;

writeln('Cac uoc cua ',n,' la: ');

while i<=n do

  begin

if n mod i=0 then write(i:4):

i:=i+1;

end;

writeln;

writeln('Cac uoc chan cua ',n,' la: ');

t:=0;

i:=1;

while i<=n do 

  begin

if (n mod i=0) then

begin

t:=t+i;

write(i:4);

end;

inc(i);

end;

writeln('Tong cac uoc chan cua ',n,' la: ',t);

readln;

end.

MinhThu
Xem chi tiết
Ngô Bá Hùng
16 tháng 4 2023 lúc 8:09

program TinhTongVaUocSo;
var
  a, b, tong, i: integer;
  laSoNguyenTo: boolean;
begin
  write('Nhap a: ');
  readln(a);
  write('Nhap b: ');
  readln(b);
  tong := a + b;
  writeln('Tong cua a va b la: ', tong);
  writeln('Uoc so cua tong la:');
  for i := 1 to tong do
  begin
    if tong mod i = 0 then
      writeln(i);
  end;
  laSoNguyenTo := true;
  if tong < 2 then
    laSoNguyenTo := false
  else
    for i := 2 to trunc(sqrt(tong)) do
      if tong mod i = 0 then
      begin
        laSoNguyenTo := false;
        break;
      end;
  if laSoNguyenTo then
    writeln('Tong a va b la so nguyen to')
  else
    writeln('Tong a va b khong phai la so nguyen to');
  readln;
end.

 

MinhThu
Xem chi tiết
Nguyễn Hoàng Duy
15 tháng 4 2023 lúc 21:05

program TinhTongVaUocCuaTong;

var a, b, tong, i: integer;
     SoNguyenTo: boolean;

begin
writeln('Nhap vao hai so a va b (a > 0, b > 0): ');
  write('a = ');
  readln(a);
  write('b = ');
  readln(b);
  tong := a + b;
  writeln('Tong cua a + b = ', tong);
  writeln('Uoc cua tong a + b: ');
  for i := 1 to tong do
  begin
    if tong mod i = 0 then
      writeln(i);
  end;
  SoNguyenTo := true;
  if tong < 2 then
  SoNguyenTo := false
  else
    for i := 2 to trunc(sqrt(tong)) do
    begin

  if tong mod i = 0 then
 begin
 SoNguyenTo := false;
        break;
      end;
    end;
   if SoNguyenTo then
    writeln('Tong a + b la so nguyen to:')
  else
    writeln('Tong a + b khong phai la so nguyen to:');
  end.

Kỳ AnH
Xem chi tiết
Nguyễn Thanh Anh
Xem chi tiết
Nguyễn Lê Phước Thịnh
17 tháng 2 2023 lúc 7:43

uses crt;

var n,i,kt,j:integer;

begin

clrscr;

readln(n);

i:=1;

while (i<n) do

begin

i:=i+1;

kt:=0;

for j:=2 to i-1 do

if i mod j=0 then kt:=1;

if kt=0 then write(i:4);

end;

readln;

end.

Nguyenquochuy
2 tháng 3 2023 lúc 19:48

Viết chương trình pascal nhập n ( n>0 ) xuất ra màn hình các số hoàn toàn từ 1-2n và cho bt có bao nhiêu số như vậy

aloooooooo
Xem chi tiết
Minh Lệ
19 tháng 2 2023 lúc 23:07

Program HOC24;

var i,n,d: integer;

begin

write('Nhap N: '); readln(n);

write('Cac uoc cua 'n,' la: ');

for i:=1 to n do if i mod n = 0 do then

begin write(i,' '); d:=d+1; end;

writeln;

write('Co ',d,' so la uoc cua ',n);

readln

end.