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.
uses crt;
var n,i,o,d:integer;
function ktnt(n:integer): integer;
var i,d:integer;
begin
d:=0;
for i:=1 to sqrt(n) do
if (n mod i=0) then d:=d+1;
if d=2 then ktnt=0
else ktnt=1;
end;
begin
readln(n);
writeln(' so nguyen to be hon hoac bang n la'); {a}
for i:=1 to n do
if ktnt(i)=0 then writeln(i);
writeln('so nguyen to nho nhat khong be hon n');
o:=n;
while o>0 do
begin
if ktnt(o)=0 then
begin
write(o);
break;
end;
o:=o+1;
end;
writeln('cặp số nguyên tố là hai số nguyên lẻ liên tiếp nhỏ hơn hoặc bằng n');
o:=0;
o:=1;
d:=0;
for i:=o+2 to n do
begin
if ktnt(i)=0 then
begin
d:=d+1;
write(i,' ');
if d<2 then continue;
end;
d:=0;
writeln;
end;
readln;
end.
uses crt;
var x,y,z,n : integer;
begin clrscr;
write('Nhap n:'); readln(n);
for x:=1 to 9 do
for y:=0 to 9 do
for z:=0 to 9 do
if n*(x+y+z) = x*100+y*10+z then
write('So thoa man de la :', x,y,z, ' ');
readln
end.
program tong;
uses crt;
var M, N, S, i: integer;
begin
clrscr;
write ('Nhap M= '); readln(M);
write ('Nhap N= '); readln(N);
s : = 0;
for i := M to N do if (i mod 2 = 0) then s:= s + i;
write (T'ong cac so chan trong pham vi tu M den N = ',s);
readln;
end.
mk mới làm tổng thui nghen
#include <bits/stdc++.h>
using namespace std;
long long n;
int main()
{
cin>>n;
if (n%2==0) cout<<"Chan";
else cout<<"Le";
return 0;
}
Bài 1:
uses crt;
var n,d,t,x,y,j,kt,i,t1,dem:integer;
st:string;
a:array[1..255]of integer;
begin
clrscr;
write('n='); readln(n);
if (0<n) and (n<1000) then
begin
{------------------------dong-1---------------------------}
str(n,st);
d:=length(st);
t:=0;
for i:=1 to d do
begin
val(st[i],x,y);
t:=t+x;
end;
writeln('tong cac chu so cua ',n,' la: ',t);
{----------------------dong-2----------------------------}
writeln('cac so nguyen to nho hon tong cac chu so cua ',n,' la: ');
dem:=0;
for i:=2 to t-1 do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then
begin
write(i:4);
dem:=dem+1;
a[dem]:=i;
end;
end;
{----------------dong-3---------------------------}
writeln;
t1:=0;
for i:=1 to dem do
t1:=t1+a[i];
writeln('tong cac so nguyen to trong dong 2 la: ',t1);
end
else writeln('vui long nhap lai');
readln;
end.
Bài 2:
uses crt;
var a,b,i,dem,j,kt:integer;
c:array[1..100]of integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
if (20<=a) and (a<=50) and (30<=b) and (b<=75) then
begin
{------------------------dong-1--------------------------}
writeln('cac so co 2 chu so chia het cho 9 la:');
for i:=10 to 99 do
if i mod 9=0 then write(i:4);
{-----------------------dong-2--------------------------}
writeln;
writeln('cac so chinh phuong lon hon ',a,' va nho hon ',b,' la: ');
for i:=a+1 to b-1 do
if trunc(sqrt(i))=sqrt(i) then write(i:4);
{-----------------------dong-3---------------------------}
writeln;
dem:=0;
for i:=2 to b do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem);
c[dem]:=i;
end;
end;
writeln('so nguyen to lon nhat nho hon ',b,' la: ',c[dem]);
end
else writeln('vui long nhap lai');
readln;
end.
Bài 3:
uses crt;
var n,d,t,i,x,y:integer;
st:string;
begin
clrscr;
write('n='); readln(n);
if (0<n) and (n<105) then
begin
{---------------------------dong-1---------------------------}
str(n,st);
d:=length(st);
writeln('so luong cac chu so cua ',n,' la: ',d);
{---------------------------dong-2--------------------------}
t:=0;
for i:=1 to d do
begin
val(st[i],x,y);
t:=t+x;
end;
writeln('tong cac chu so cua ',n,' la: ',t);
{---------------------------dong-3------------------------}
writeln('phan so toi gian cua ',n,' la: 1/',n);
write('so dao nguoc cua ',n,' la: ');
for i:=d downto 1 do
write(st[i]);
end
else writeln('vui long nhap lai');
readln;
end.
Câu 1:
Program hotrotinhoc;
var i,tog,n: integer;
function tong(x: integer): integer;
var k,t: longint;
begin
t:=0;
while x<>0 do
begin
k:=x mod 10;
t:=t+k;
x:=x div 10;
end;
tong:=t;
end;
function nt(a: integer): boolean;
var j: integer;
begin
nt:=true;
if (a=2) or (a=3) then exit;
nt:=false;
if (a=1) or (a mod 2=0) or (a mod 3=0) then exit;
j:=5;
while (j<=trunc(sqrt(a))) do
begin
if (a mod j=0) or (a mod (j+2)=0) then exit;
j:=j+6;
end;
nt:=true;
end;
begin
write('Nhap so nguyen N :'); readln(n);
writeln('Tong cac chu so cua N la :',tong(n));
write('Cac so nguyen to nho hon tong cac chu so cua N la :');
for i:=1 to tong(n) do if nt(i) then
begin
write(i,' ');
tog:=tog+i;
end;
writeln;
write('Tong cac so nguyen to trong dong 2 la :',tog);
readln
end.
var A:
array[1..n] of int64;
i, n, count: integer;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
for i := 1 to n do
begin
write('Nhap phan tu thu ', i, ': ');
readln(A[i]);
end;
count := 0;
for i := 1 to n do
if A[i] > 0 then
count := count + 1;
writeln('So luong cac so nguyen duong trong mang la: ', count); end.
Ngôn ngữ: C++
#include <bits/stdc++.h>
using namespace std;
long long n;
long long minx=LLONG_MAX;
long long a[100000];
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=2;i<=n;i++){
minx=min(minx,a[i]-a[i-1]);
}
cout<<minx;
return 0;
}