BT1_4: Nhập vào số nguyên n
a) Xuất ra số chẵn lớn nhất bé hơn n
b)Xuất ra số chia hết cho 5 nhỏ nhất lớn hơn n
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
Program Nguyen_to;
Var n,i:integer;
Function NT(n:integer):Boolean;
Var ok: Boolean;
i: integer;
Begin ok:=true;
for i:=2 to n-1 do if (n mod i)= 0 then ok:=ok and false;
if n < 2 then NT:=false else NT:=ok;
End;
Begin Write('Nhap n: ');
Readln(n); i:=n;
Repeat i:=i+1;
Until NT(i);
Write('So nguyen to nho nhat lon hon ',n, 'la: ',i);
Readln End.
câu 2
uses crt;
const so: set of char=['0','1','2','3','4','5','6','7','8','9'];
var a:array[1..100] of integer;
st,b:string;
c,l,i,n,j:integer;
s, Max: integer;
begin clrscr;
write('Nhap xau:');
readln(st);
l:=length(st);
i:=1;
n:=0;
repeat if (st[i] in so) then begin b:='';
repeat b:=b+st[i];
inc(i);
until (not(st[i] in so)) or (i>l);
inc(n);
val(b,a[n],c);
end;
inc(i);
until i>l;
Max:=a[1];
for i:=2 to n do If Max<A[i] Then Max:=A[i];
Writeln('Phan tu lon nhat cua mang:', Max);
readln;
end.
uses crt;
var a,b,c,d:array[1..100]of integer;
n,i,dem,t,max,min,j,dem1,kt,dem2,dem3,kt1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Phan tu dau tien la: ',a[1]);
writeln('Phan tu cuoi cung la: ',a[n]);
dem:=0;
for i:=1 to n do
if a[i] mod 4=0 then inc(dem);
writeln('So luong phan tu chia het cho 4 la: ',dem);
t:=0;
for i:=1 to n do
if (a[i] mod 2=0) and (a[i]>10) then t:=t+a[i];
writeln('Tong cac so chan va lon hon 10 la: ',t);
dem1:=0;
for i:=1 to n do
if sqrt(a[i])=trunc(sqrt(a[i])) then
begin
inc(dem1);
b[dem1]:=a[i];
end;
writeln;
writeln('So luong so chinh phuong trong mang la: ',dem1);
if dem1>0 then
begin
writeln('Cac so chinh phuong co trong mang la: ');
for i:=1 to dem1 do
write(b[dem1]:4);
end;
writeln;
kt:=0;
for i:=1 to n do
if a[i] mod 2<>0 then kt:=1;
if kt=0 then writeln('Day la mang chan')
else writeln('Day khong la mang chan');
readln;
end.
program TimSoLonHonA;
var
a: array of integer;
n, i, x: integer;
begin
write('Nhap so phan tu cua day so: ');
readln(n);
SetLength(a, n);
for i := 0 to n - 1 do
begin
write('Nhap gia tri phan tu thu ', i + 1, ': ');
readln(a[i]);
end;
write('Nhap vao mot so nguyen bat ky: ');
readln(x);
writeln('Cac so lon hon ', x, ' la: ');
for i := 0 to n - 1 do
begin
if (a[i] > x) then
writeln(a[i]);
end;
end.
uses crt;
var a:array[1..250]of integer;
i,n,max:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('Gia tri lon nhat la: ',max);
writeln('Vi tri cua no trong mang la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
readln;
end.
1)
var a,b : integer;
begin
writeln('nhap a va b =');
readln(a,b);
if a>b then writeln('So lon hon la a') else writeln('so lon hon la b');
if a=b then writeln('a va b bang nhau');
readln
end.
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.
#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;
}