nhập số nguyên N viết công thức in ra màn hình tất cả các ước của n. hướng dẫn cho i chạy từ 1 tới N nếu N chia hết cho i thì in ra màn hình i
viết đoạn chương trình in các ước của số nguyên dương n ra màn hình với n được nhập từ bàn phím. (gợi ý: cho vòng lặp for có biến đếm i chạy từ 1-n, kiểm tra xem biến i có là ước ước số của n khi n chia hết cho i) *
for i:=1 to n do
if n mod i=0 then write(i:4);
Chương trình đầy đủ:
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
if n mod i=0 then write(i:4);
readln;
end.
. Viết chương trình tính tổng bình phương của n từ 1 đến 30. In kết quả ra màn hình.
Viết chương trình nhập vào một số nguyên rồi in ra màn hình tất cả các ước số của số đó.
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;
}
2.viết chương trình nhập vào số nguyên dương n. A. Tìm và in ra màn hình các số từ 1 đến n chia hết cho 2. .B. tìm và in ra màn hình số từ 1-n ko chia hết cho 2
Program HOC24;
var i,n: integer;
begin
write('Nhap N: '); readln(n);
write('Cac so tu 1 den ',n,' chia het cho 2 la: ');
for i:=1 to n do if i mod 2=0 then write(i,' ');
writeln;
for i:=1 to n do if i mod 2=1 then write(i,' ');
readln
end.
Bài 1: Viết công thức nhập vào một số thự nhiên n. Sau đó kiểm tra xem số n có phải là số nguyên tố hay không?
Bài 2: Viết công thức vào 1 số tự nhiên n và in ra màn hình tất cả các ước
Bài 1:
uses crt;
var n,i,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
kt:=0;
for i:=2 to n-1 do
if n mod i=0 then kt:=1;
if (kt=0) and (n>1) then writeln(n,' la so nguyen to')
else writeln(n,' khong la so nguyen to');
readln;
end.
Bài 2:
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
if n mod i=0 then write(i:4);
readln;
end.
a)
uses crt;
var i,n:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n<100;
if n mod 2=0 then
begin
for i:=0 to n do
if i mod 2=0 then write(i:4);
end
else writeln(n,' khong la so chan');
readln;
end.
b)
uses crt;
var i,n:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n<100;
if n mod 2=1 then
begin
for i:=1 to n do
if i mod 2=1 then write(i:4);
end
else writeln(n,' khong la so le');
readln;
end.
Viết Chương Trình Pascal Cho Nhập N Nguyên , Dương Từ Bàn Phím . In ra màn hình : -Các Ước Của N Không Kể N -Xác Định N Có Phải Là Số Hoàn Hảo -Tất Cả Số Hoàn Hảo Trong Phạm Vi Từ 1-> N
program bai_toan;
var
N, i, sum: integer;
begin
write('Nhap so N: ');
readln(N);
write('Cac uoc cua ', N, ' khong ke ', N, ' la: ');
for i := 1 to N - 1 do
if N mod i = 0 then
write(i, ' ');
writeln;
sum := 0;
for i := 1 to N - 1 do
begin
if N mod i = 0 then sum := sum + i;
end;
if sum = N then writeln(N, ' la so hoan hao')
else writeln(N, ' khong phai la so hoan hao');
writeln;
writeln('Tat ca so hoan hao trong pham vi 1 -> ', N, ' la:');
for i := 1 to N do
begin
sum := 0;
for j := 1 to i - 1 do
begin
if i mod j = 0 then sum := sum + j;
end;
if sum = i then writeln(i);
end;
readln;
end.
1. Viết chương trình nhập vào một số nguyên dương n và in ra màn hình dãy số tự nhiên từ 1 tới n. 2. Viết chương trình nhập vào một số nguyên n và in ra màn hình các số nguyên chẵn trong khoảng từ 1 tới n.
1. Uses crt;
var n,i: integer;
begin clrscr;
readln(n);
for i:=1 to n do write(i:3);
readln;
end.
2. Uses crt;
var n,i: integer;
begin clrscr;
readln(n);
for i:=1 to n do if(i mod 2 = 0) then write(i:3);
readln;
end.
1. Uses crt;
var n,i: integer;
begin clrscr;
readln(n);
for i:=1 to n do write(i:3);
readln;
end.
2. Uses crt;
var n,i: integer;
begin clrscr;
readln(n);
for i:=1 to n do if(i mod 2 = 0) then write(i:3);
readln;
end.
1.
program InDaySoTuNhien;
var n, i: integer;
begin
write('Nhap so nguyen duong n: ');
readln(n);
writeln('Day so tu 1 den ', n, ' la:');
for i := 1 to n do
write(i, ' ');
end.
2.
program InSoChan;
var
n, i: integer;
begin
write('Nhap so nguyen n: ');
readln(n);
writeln('Cac so nguyen chan trong khoang tu 1 den ', n, ' la:');
for i := 1 to n do
begin
if i mod 2 = 0 then
write(i, ' ');
end;
end.
viết chương trình nhập số nguyên n từ bàn phím.
-in ra màn hình các số chia hết cho 3, mỗi số cách nhau một kí tự trống
-in ra màn hình số các số chia hết cho 3
#include <bits/stdc++.h>
using namespace std;
long long a[10000],i,n,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
dem=0;
for (i=1; i<=n; i++)
if (a[i]%3==0)
{
cout<<a[i]<<" ";
dem++;
}
cout<<endl;
cout<<dem;
return 0;
}
Chương trình C++
Nhập từ bản phim dãy gồm n số nguyên (n<=100).
* In ra màn hình dãy các số chẵn trong dãy đã nhập
* In ra màn hình giá trị trung bình cộng của dây các số chân từ dãy đã nhập
• In ra màn hình tổng các số lẻ và chia hết cho 3
#include <bits/stdc++.h>
using namespace std;
long long n,i,a[1000],t,dem,t1;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]%2==0) cout<<a[i]<<" ";
cout<<endl;
t=0;
dem=0;
for (i=1; i<=n; i++)
if (a[i]%2==0)
{
t=t+a[i];
dem++;
}
cout<<fixed<<setprecision(2)<<(t*1.0)/(dem*1.0)<<endl;
t1=0;
for (i=1; i<=n; i++)
if (a[i]%2!=0 || a[i]%3==0) t1+=a[i];
cout<<t1;
return 0;
}