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:integer;
m:real;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (1<=n) and (n<=30000);
m:=0;
for i:=1 to n do
m:=m+sqrt(i);
writeln('m=',m:4:2);
readln;
end.
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=1 to n do
if i mod 6=0 then s:=s+i;
writeln(s);
readln;
end.
Bài 2:
uses crt;
var a,b,c,ucln,i:integer;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
write('c='); readln(c);
while a<>b do
begin
if a>b then a:=a-b
else b:=b-a;
end;
ucln:=a;
while ucln<>c do
begin
if ucln>c then ucln:=ucln-c
else c:=c-ucln;
end;
writeln(ucln);
readln;
end.
1 không
2
Program UCLN;
uses crt;
var a,b : integer;
begin
write ('nhap so a la ');readln (a);
write ('nhap so b la ');readln (b);
while a < > b do
if a >b then a := a - b else b := b - a ;
write ( ' UCLN la :' , a );
readln
end.
1:
#include <bits/stdc++.h>
using namespace std;
int n,i;
bool kt;
int main()
{
cin>>n;
kt=true;
for (i=2; i*i<=n; i++)
if (n%i==0) kt=false;
if (kt==true && n>1) cout<<"La so nguyen to";
else cout<<"Khong la so nguyen to";
return 0;
}
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.
1) var a,b,c,d,h,g:integer;
begin
write('a=');readln(a);
write('b=');readln(b);
write('c=');readln(c);
write('d=');readln(d);
h:=a;
if b>h then h:=b;
if c>h then h:=c;
if d>h then h:=d;
g:=a;
if b<g then g:=b;
if c<g then g:=c;
if d<g then g:=d;
writeln(' So lon nhat trong 4 so la: ',h);
writeln(' So be nhat trong 4 so la: ',g);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x,y;
cout<<"Nhap n="; cin>>n;
x=n;
y=n+1;
if (x%2==0) cout<<x-2<<endl;
else cout<<x-1<<endl;
if (y%5==0) cout<<y;
else {
while (y%5!=0)
y++;
cout<<y;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,ln,nn,t;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
for (i=1; i<=n; i++) t+=a[i];
ln=a[1];
nn=a[1];
for (i=2; i<=n; i++)
{
ln=max(ln,a[i]);
nn=min(nn,a[i]);
}
cout<<t<<endl;
cout<<ln<<" "<<nn;
return 0;
}
Var a:array[1..200] of integer;
i,n,s,max,min:integer;
Begin
Write('Nhap so luong phan tu n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
s:=a[1];
max:=a[1];
min:=a[1];
For i:=2 to n do
Begin
s:=s+a[i];
If a[i] > max then max:=a[i];
If a[i] < min then min:=a[i];
End;
Writeln('Tong la ',s);
Writeln('So lon nhat la ',max);
Write('So nho nhat la ',min);
Readln;
End.
program TimSoLonNhat;
var
N, i, j, count: integer;
isPrime: boolean;
function IsPrimeNumber(num: integer): boolean;
var
k: integer;
begin
if num < 2 then
begin
IsPrimeNumber := False;
Exit;
end;
for k := 2 to Trunc(Sqrt(num)) do
begin
if (num mod k) = 0 then
begin
IsPrimeNumber := False;
Exit;
end;
end;
IsPrimeNumber := True;
end;
begin
Write('Nhap gia tri N: ');
Readln(N);
for i := N - 1 downto 2 do
begin
count := 0;
isPrime := IsPrimeNumber(i);
if isPrime then
begin
for j := 2 to Trunc(Sqrt(i)) do
begin
if (i mod j) = 0 then
begin
count := count + 1;
end;
end;
if count = 1 then
begin
writeln('So lon nhat nho hon ', N, ' co duy nhat 2 uoc nguyen to la: ', i);
break;
end;
end;
end;
Readln;
end.