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.
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:
#include <bits/stdc++.h>
using namespace std;
long long n,i;
bool kt;
int main()
{
cin>>n;
if (n>1)
{
kt=true;
for (i=2; i*i<=n; i++)
if (n%i==0) kt=false;
if (kt==true) cout<<n<<" la so nguyen to";
else cout<<n<<" khong la so nguyen to";
}
else cout<<n<<" khong la so nguyen to";
return 0;
}
Bài 1:
uses crt;
var n,i,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t:=0;
for i:=0 to n do
if i mod 2=0 then t:=t+a[i];
writeln('Tong cac so chan nho hon hoac bang ',n,' la: ',t);
readln;
end.
Bài 2:
uses crt;
var i,n,dem:integer;
begin
clrscr;
repeat
write('Nhap n=');readln(n);
until n>0;
dem:=0;
for i:=0 to n do
if i mod 3=0 then inc(dem);
writeln('So so chia het cho 3 nho hon hoac bang ',n,' la: ',dem);
readln;
end.
Bài 3:
uses crt;
var a:real;
n,i:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n>0;
a:=0;
for i:=1 to n do
a:=a+1/(i*(2*i+1));
writeln('Ket qua la: ',a:4:2);
readln;
end.
Bài 4:
uses crt;
var n,i,kt:integer;
begin
clrscr;
Repeat
write('Nhap n='); readln(n);
Until n>1;
kt:=0;
for i:=2 to n-1 do
if n mod i=0 then kt:=1;
if kt=0 then writeln(n,' la so nguyen to')
else writeln(n,' khong la so nguyen to');
readln;
end.
1
Uses crt;
Var t,n,i:longint;
Begin
clrscr;
write('nhap vào số n: ');readln(n);
while n<1 do readln(n);
for i:=1 to n do t:=t*i;
write('tich tren co ket qua la: 't);
readln;
End.
2(bài này sử dụng mảng nhé)
Uses Crt;
Type Mang = ARRAY[1..50] Of Integer;
Var A:Mang;
N,i,Max:Integer;
Begin
Write('Nhap N='); Readln(N);
while N<1 do readln(N);
For i:=1 To N Do
Begin
Write('A[',i,']='); Readln(A[i]);
End;
Max:=A[1];
For i:=2 To N Do
If Max<A[i] Then Max:=A[i];
Writeln('so lon nhat trong day N:', Max);
Readln;
End.
3
Uses crt;
Var a:array[1..20]of integer;i,N,max,min:integer;
Begin
Clrscr;
Write(‘Nhap so phan tu cua day n=’);readln(n); For i:=1 to n do
Begin
Write(‘Nhap a[‘,i,’]=’);readln(a[i]);
End;
Min:=a[1]; Max:=a[1]; For i:=1 to N do
Begin
If (Min > a[i]) then Min:=a[i];
If (Max < a[i]) then Max:=a[i];
End;
Writeln('Day so vua nhap la: '); Writeln('————————-'); For i:=1 to N do
Write(a[i]:4); Writeln;
Writeln('Gia tri lon nhat la:',Max); Writeln('gia tri nho nhat la:',Min);
Readln;
End.
kiểm tra xem đúng ko nhé!
uses crt;
var a,b:longint;
st:string;
nt:array[1..100]of int64;
t,i,j,dem,kt,kt1,d,dnt:integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
dem:=0;
for t:=a to b do
begin
str(t,st);
kt:=0;
d:=length(st);
for i:=1 to d do
if st[i]<>st[d-i+1] then kt:=1;
if kt=0 then
begin
dem:=dem+1;
nt[dem]:=t;
end;
end;
dnt:=0;
for i:=1 to dem do
begin
kt1:=0;
for j:=2 to nt[i]-1 do
if nt[i] mod j=0 then kt1:=1;
if kt1=0 then dnt:=dnt+1;
end;
writeln('so luong cac so nguyen to doi xung thoa man lon hon hoac bang ',a,' va nho hon hoac bang ',b,' la: ',dnt);
readln;
end.
uses crt;
var a,b:longint;
st:string;
nt:array[1..100]of int64;
t,i,j,dem,kt,kt1,d,dnt:integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
dem:=0;
for t:=a to b do
begin
str(t,st);
kt:=0;
d:=length(st);
for i:=1 to d do
if st[i]<>st[d-i+1] then kt:=1;
if kt=0 then
begin
dem:=dem+1;
nt[dem]:=t;
end;
end;
dnt:=0;
for i:=1 to dem do
begin
kt1:=0;
for j:=2 to nt[i]-1 do
if nt[i] mod j=0 then kt1:=1;
if kt1=0 then dnt:=dnt+1;
end;
writeln('so luong cac so nguyen to doi xung thoa man lon hon hoac bang ',a,' va nho hon hoac bang ',b,' la: ',dnt);
readln;
end.