Sử dụng Python để Viết chương trình cho người dùng nhập vào số nguyên dương n, rồi kiểm tra các số nhập vào có phải là số nguyên tố hay không? Và đếm xem có bao nhiêu số nguyên tố được nhập vào thì in ra màn hình.
a.Viết chương trình nhập vào 1 số nguyên n in ra màn hình các số chẵn in ra từ 1 đến n b.Viết chương trình nhập 1 dãy số nguyên n phần tử kiểm tra xem n có phải số nguyên tố hay không
c.Viết chương trình nhập vào 1 dãy số nguyên gồm n phần tử in ra màn hình các số chia hết cho 2
d. Viết chương trình 1 dãy số nguyên gồm n phần tử in ra màn hình số nhỏ nhất có trong dãy.
c:
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i;
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]<<" ";
return 0;
}
d:
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,nn;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
nn=a[1];
for (i=1; i<=n; i++) nn=min(nn,a[i]);
cout<<nn;
return 0;
}
viết chương trình nhập vào một dãy số nguyên n phần tử, n nhập từ bàn phím.
a) In ra màn hình dãy số vừa nhập xếp theo thứ tự tăng dần.
b) In ra màn hình các số nguyên tố trong dãy số vừa nhập và đếm xem đã nhập vào bao nhiêu số nguyên tố.
giúp mk vs mn.KO DÙNG C+
Viết chương trình nhập số tự nhiên n<m(1<n<m<100000).In ra màn hình.
1.Kiểm tra số n có phải là số nguyên tố hay ko.
2.Đếm,tính tổng và in ra các số nguyên tố <n.
3.Đếm,tính tổng và in ra các số nguyên tố <m và >n.
4.In ra m số nguyên tố đầu tiên.
uses crt;
var n,m,i,dem,t,t1,d1:integer;
//chuongtrinhcon
function ktnt(var n:integer):boolean;
var i:integer;
kt:boolean;
begin
kt:=true;
for i:=2 to trunc(sqrt(n)) do
if n mod i=0 then kt:=false;
if (kt=true) then ktnt:=true
else ktnt:=false;
end;
//chuongtrinhchinh
begin
clrscr;
readln(n,m);
if (ktnt(n)=true) then writeln(n,' la so nguyen to')
else writeln(n,' ko la so nguyen to');
dem:=0;
t:=0;
for i:=2 to n do
if (ktnt(i)=true) then
begin
write(i:4);
t:=t+i;
dem:=dem+1;
end;
writeln;
writeln(t,' ',dem);
t1:=0;
d1:=0;
for i:=n to m do
if ktnt(i)=true then
begin
write(i:4);
t1:=t1+i;
inc(d1);
end;
writeln;
writeln(t1,' ',d1);
readln;
end.
1)viết chương trình xuất ra các bội số của B trong phạm vị từ 1 đến N, với giá trị B, N được nhập vào từ bàn phím
2) nhập số nguyên n, viết chương trình xem số n có phải là số nguyên tố không
3)viết chương trình kiểm tra C có phải số hoàn hảo hay không
2:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,i,kt=0;
cin>>n;
for (int i=2; i*i<=n; i++)
if (n%i==0) kt=1;
if (kt==0) cout<<"YES";
else cout<<"NO";
}
viết chương trình nhập vào 1 số nguyên N . In ra màn hình cho biết N có phải là số nguyên tố hay không ?
Var i,n,dem:integer;
begin
write('Nhap n = ');readln(n);
for i:=1 to n do
if n mod i = 0 then dem:=dem+1;
if dem=2 then write(n,' la so nguyen to')
else write(n,' khong la so nguyen to');
readln;
end.
1Cho số nguyên dương N ,đếm số cách phân tích N thành tổng hai số nguyên tố .
2 Viết chương trình nhập vào số nguyên dương N.
a) Xuất ra màn hình N có phải là số nguyên tố đối xứng hay không.
b) Thông báo ra màn hình số nguyên tố đối xứng nhỏ nhất lớn hơn N.
mong các bạn giúp mình với ạ.
Câu 1:
uses crt;
var n,i,dem,j,kt1,kt2,a,b,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
dem:=0;
if n mod 2=1 then
begin
a:=2;
b:=n-a;
kt:=0;
for i:=2 to trunc(sqrt(b)) do
if b mod i=0 then kt:=1;
if kt=0 then inc(dem);
end
else begin
for i:=2 to n div 2 do
begin
a:=i;
b:=n-i;
kt1:=0;
kt2:=0;
for j:=2 to trunc(sqrt(a)) do
if a mod j=0 then kt1:=1;
for j:=2 to trunc(sqrt(b)) do
if b mod j=0 then kt2:=1;
if (kt1=0) and (kt2=0) then inc(dem);
end;
end;
writeln('So cach phan tich ',n,' thanh tong hai so nguyen to la: ',dem);
readln;
end.
Câu 2:
uses crt;
var n,x:integer;
{-----------------ham-kiem-tra-nguyen-to-----------------}
function ktnt(x:integer):boolean;
var kt:boolean;
i:integer;
begin
kt:=true;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then
begin
kt:=false;
break;
end;
if kt=true then ktnt:=true
else ktnt:=false;
end;
{---------------ham-kiem-tra-so-doi-xung---------------}
function ktdx(x:integer):boolean;
var kt:boolean;
d,i:integer;
st:string;
begin
str(x,st);
d:=length(st);
kt:=true;
for i:=1 to d do
if st[i]<>st[d-i+1] then
begin
kt:=false;
break;
end;
if kt=true then ktdx:=true
else ktdx:=false;
end;
{--------------chuong-trinh-chinh---------------}
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n>0;
if (ktnt(n)=true) and (ktdx(n)=true) then writeln(n,' la so nguyen to doi xung')
else writeln(n,' khong la so nguyen to doi xung');
x:=n+1;
repeat
x:=x+1;
until (ktnt(x)=true) and (ktdx(x)=true);
writeln('So nguyen to doi xung nho nhat lon hon ',n,' la: ',x);
readln;
end.
bài 1;
const
fi='phantich.inp'
fo='phantich.out'
var f,g:text;i,n,d:longint;
function nt(n:longint):boolean;
var i:longint;
begin
if (n<2) then exit (false);
for i:=2 to trunc(sqrt(n)) do
if (n mod i=0) then exit (false);
exit (true);
end;
begin
assign(f,fi);reset(f);
assign(g,fo);rewrite(g);
readln(f,n);
d:=0;
for i:=1 to n div 2 do
if nt(i) and nt(n-i) then inc(d);
writeln(g,'co ',d,' cach phan tich');
close(f);close(g);
end.
bài 2:
const
fi='primenumber.inp'
fo='primenumber.out'
var f,g:text;n:longint;
function nt(n:longint):boolean;
var i:longint;
begin
if (n<2) then exit (false);
for i:=2 to trunc(sqrt(n)) do
if (n mod i=0) then exit (false);
exit (true);
end;
function check(n:longint):boolean;
var s,m:longint;
begin
s:=0;m:=n;
while (n>0) do
begin
s:=s*10+(n mod 10);
n:=n div 10;
end;
if (s=m) and (nt(s)=true) then exit (true);
exit (false);
end;
begin
assign(f,fi);reset(f);
assign(g,fo);rewrite(g);
readln(f,n);
if check(n) then writeln(g,'la so nguyen to doi xung') else
writeln(g,'khong la so nguyen to doi xung');
repeat
inc(n);
until (check(n)=true);
writeln(g,'so do la : ',n);
close(f);close(g);
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.