Những câu hỏi liên quan
Ái Cầm Trần
Xem chi tiết
Phúc Hưng 123 Lê Trần 12...
Xem chi tiết
Trần nguyên sang
Xem chi tiết
Họ Và Tên
Xem chi tiết
Nguyễn Lê Phước Thịnh
14 tháng 1 2021 lúc 22:01

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ình luận (1)
hoang
11 tháng 1 2023 lúc 22:53

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ình luận (0)
Trần Đức Huy
Xem chi tiết
Võ Quốc Bảo
14 tháng 3 2023 lúc 20:34

#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int a[32];
    int n,i,s;
    cout<<"nhap so phan tu cua mang ";
    cin>>n;
    cout<<"nhap cac phan tu cua mang ";
    for (i=1; i<=n; i++)
    {
        s=0;
        cin>>a[i];

    }
    for(i=1; i<=a[i]; i++) s=s+i;

    cout<<s;
    return 0;
}

 

 

Bình luận (0)
Minh Lệ
14 tháng 3 2023 lúc 21:23

Program HOC24;

var i,n: integer;

a: array[1..1000] of integer;

t: longint;

begin

write('Nhap n: '); readln(n);

for i:=1 to n do

begin

write('Nhap so thu ',i,': '); readln(i);

end;

t:=0;

for i:=1 to n do t:=t+a[i];

write('Tong la: ',t);

readln

end.

Bình luận (0)
Lê Gia Anh
19 tháng 3 2023 lúc 20:26

ngu thế mà cũng ko lm được dcd

Bình luận (0)
Nguyễn Phú Trọng
Xem chi tiết
Nguyễn Lê Phước Thịnh
22 tháng 12 2020 lúc 22:28

uses crt;

var a,vtmax,vtmin:array[1..100]of integer;       

 n,i,max,min,dem,t,dem1,t1,dem2,t2,dem3,t3,dem4,t4,k: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('So lon nhat trong day la: ',max);

dem:=0;

t:=0;

for i:=1 to n do 

if max=a[i] then     

begin       

inc(dem);

t:=t+a[i];       

vtmax[dem]:=i;     

end;

if dem>1 then   

begin     

writeln('Tong cac so max la: ',t);     

writeln('Cac vi tri co so max la: ');     

for i:=1 to dem do       

write(vtmax[i]:4);   

end;

min:=a[1];

for i:=1 to n do 

if min>a[i] then min:=a[i];

writeln('So nho nhat trong day la: ',min);

dem1:=0;

t1:=0;

for i:=1 to n do 

if min=a[i] then     

begin       

inc(dem1);       

t1:=t1+a[i];       

vtmin[dem1]:=i;     

end;

if dem1>1 then   

begin     

writeln('Tong cac so min la: ',t1);     

writeln('Cac vi tri co so min la: ');     

for i:=1 to dem1 do       

write(vtmin[i]:4);   

end;

write('Nhap k='); readln(k);

dem2:=0;

t2:=0;

for i:=1 to n do 

if (i mod 2=0) and (a[i] mod k=0) then     

begin       

dem2:=dem2+1;       

t2:=t2+a[i];     

end;

writeln('So phan tu o vi tri chan trong day la boi cua ',k,' la: ',dem2);

writeln('Tong cac so o vi tri chan trong day la boi cua ',k,' la: ',t2);

dem3:=0;

t3:=0;

for i:=1 to n do 

if (i mod 2=1) and (k mod a[i]=0) then     

begin       

inc(dem3);       

t3:=t3+a[i];     

end;

writeln('So phan tu o vi tri le trong day la uoc cua ',k,' la: ',dem3);

writeln('Tong cac so o vi tri le trong day la uoc cua ',k,' la: ',t3);

dem4:=0;

t4:=0;

for i:=1 to n do 

if (a[i]+k=1) or (a[i]=k+1) then     

begin       

inc(dem4);       

t4:=t4+a[i];     

end;

writeln('So phan tu la anh em cua ',k,' trong day la: ',dem4);

writeln('Tong cac phan tu la anh em cua ',k,' trong day la: ',t4);

readln;

end.

Bình luận (0)
Nguyễn Văn Hùng
Xem chi tiết
Ngô Bá Hùng
25 tháng 4 2023 lúc 23:27

program UocChungLonNhat;
var
  a, b: integer;

function UCLN(a, b: integer): integer;
begin
  if b = 0 then
    UCLN := a
  else
    UCLN := UCLN(b, a mod b);
end;

begin
  write('Nhập số nguyên dương a: ');
  readln(a);
  write('Nhập số nguyên dương b: ');
  readln(b);

  writeln('UCLN của ', a, ' và ', b, ' là ', UCLN(a, b));
end.

Bình luận (0)
Linh Đan
Xem chi tiết
Võ Đức Dũng
17 tháng 9 2021 lúc 21:33

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.

Bình luận (1)
Võ Đức Dũng
17 tháng 9 2021 lúc 21:39

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.

Bình luận (0)
lam nguyen
Xem chi tiết
Nguyễn Lê Phước Thịnh
3 tháng 12 2021 lúc 22:14

#include <bits/stdc++.h>

using namespace std;

long long n;

int main()

{

cin>>n;

if (n<0) cout<<"la so am";

else cout<<"la so duong";

return 0;

}

Bình luận (0)