viết chương trình in ra các ước của n
Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
![](https://rs.olm.vn/images/avt/0.png?1311)
![](https://rs.olm.vn/images/avt/0.png?1311)
uses crt;
var n,i:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
if n mod i=0 then write(i:4);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
2:
#include <bits/stdc++.h>
using namespace std;
long long n,i;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
if (n%i==0) cout<<i<<" ";
return 0;
}
![](https://rs.olm.vn/images/avt/0.png?1311)
Tham khảo:
program tim_uoc;
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n: ');readln(n);
if (n<0) then
begin
writeln('So nhap vao khong thoa man.');
write('Nhap lai n: ');readln(n);
end;
writeln('Cac uoc so cua ',n,' tu 1 den ',n,' la: ');
for i:=1 to n do
if ( (n mod i) = 0 ) then write(i,' ');
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
uses crt;
var n,i,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t:=0;
for i:=1 to n do
if n mod i=0 then
begin
write(i:4);
t:=t+i;
end;
writeln;
writeln('Tong cac uoc cua ',n,' la: ',t);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
uses crt;
var i,n:integer;
begin
clrscr;
readln(n);
for i:=1 to n do if n mod i=0 then write(i:4);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
program TongUoc;
uses crt;
var
N, i, Tong: integer;
begin
clrscr;
Tong := 0;
write('Nhap so tu nhien N: ');
readln(N);
// Tinh tong cac uoc cua N
for i := 1 to N do
begin
if N mod i = 0 then
begin
Tong := Tong + i;
end;
end;
writeln('Tong cac uoc cua ', N, ' la: ', Tong);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
c++:
#include <iostream> //tim tat ca uoc cua n.using namespace std;
int main() {
int n;
cout << "Nhap so n: ";
cin >> n;
cout << "Tat ca cac uoc cua so " << n << " la ";
for(int i = 1; i <= n; i++) {
if(n % i == 0) {
cout << i << " ";
}
}
return 0;
}
![](https://rs.olm.vn/images/avt/0.png?1311)
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.
program tim_uoc;
uses crt;
var i,n:longint;
begin
clrscr;
write('nhap so n:');readln(n);
for i:=1 to n do
if n mod i=0 then write(i);
readln;
end.