Những câu hỏi liên quan
phạm hương trà
Xem chi tiết
Công Chúa Sakura
4 tháng 1 2017 lúc 22:32

a)

uses crt;

VAR

n, d, i: integer;

BEGIN

clrscr;

Writeln ('Nhap vao n='); readln (n);

d : = 1;

For i: = 1 to n do

d: = d*i;

Writeln ('d=',d);

Readln;

END.

c)

uses crt;

VAR

n, i, demuoc: integer;

BEGIN

clrscr;

Writeln ('Nhap vao n='); readln (n);

demuoc: = 0;

For i: = 1 to n do

If n mod i = 0 then

demuoc : = demuoc + 1;

If demuoc = 2 then

Writeln ('n la so nguyen to')

ELSE

Writeln ('n khong phai la so nguyen to');

Readln ;

END.

Còn phần b bạn tự nghĩ nha!

Chúc bạn học tốt!

Bình luận (0)
Trần Long
Xem chi tiết
Nguyen
Xem chi tiết
Nguyễn Lê Phước Thịnh
1 tháng 4 2021 lúc 22:38

1:

const fi='Dulieu.txt'

fo='ketqua.txt'

var f1,f2:text;

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

i,n:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

n:=0;

while not eof(f1) do 

  begin

inc(n);

read(f1,a[n]);

end;

for i:=1 to n do 

  if (a[i]>0) and (a[i] mod 2=0) then write(f2,a[i]:4);

close(f1);

close(f2);

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
1 tháng 4 2021 lúc 22:40

P/s: Cái này mình viết chương trình chính thôi nhé, còn hàm và thủ tục bạn tự viết nhé(chỉ cần lấy ý tưởng trong chương trình chính ra viết là được rồi)

2:

uses crt;

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

i,n,t:integer;

begin

clrscr;

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

for i:=1 to n do

 begin

write('A[',i,']='); readln(a[i]);

end;

t:=0;

for i:=1 to n do 

  if a[i]>=0 then t:=t+a[i];

writeln(t);

readln;

end.

Bình luận (1)
Trần Long
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)
Oanh Kim
Xem chi tiết
Nguyễn Hoàng Duy
22 tháng 3 2023 lúc 17:01

python

n = int(input("Nhập số nguyên dương N: "))
found = False

for i in range(1, n//2+1):
    sum = i
    j = i + 1
    while sum < n:
        sum += j
        j += 1
    if sum == n:
        found = True
        start = i
        end = j - 1
        break

if found:
    print(n, "có tổng của nhiều số nguyên dương liên tiếp:")
    for k in range(start, end+1):
        print(k, end=" ")
else:
    print(n, "không có tổng của nhiều số nguyên dương liên tiếp.")

Bình luận (0)
nguyễn thị như ý
Xem chi tiết
nguyễn an phát
17 tháng 4 2021 lúc 20:14

program tim_uoc;

uses crt;

var n,i,j:longint;

begin

clrscr;

write('nhap so n:');readln(n);

write('cac uoc cua n la:');

for i:=1 to n do

if n mod i=0 then write(i:3);

writeln;

j:=0;

for i:=1 to n do

if n mod i=0 then j:=j+1;

if j=2 then writeln(n,' la so nguyen to')

else writeln(n,' khong phai la so nguyen to');

readln;

end.

Bình luận (0)
Vochehoang
Xem chi tiết
Nguyễn Lê Phước Thịnh
13 tháng 4 2021 lúc 12:11

Câu 1: 

uses crt;

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

i,n,t:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

write('A[',i,']='); readln(a[i]);

end;

t:=0;

for i:=1 to n do 

  t:=t+a[i];

writeln(t);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
13 tháng 4 2021 lúc 12:12

Câu 2: 

uses crt;

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

i,n,x,dem,kt:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

write('A[',i,']='); readln(a[i]);

end;

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

kt:=0;

dem:=0;

for i:=1 to n do 

if a[i]=x then 

begin

kt:=1;

write(i:4);

inc(dem);

end;

if kt=0 then writeln('Khong co ',x,' trong day');

writeln(x,' xuat hien ',dem,' lan trong day');

readln;

end.

Bình luận (0)
Lê Huỳnh Nhân
Xem chi tiết
Nguyễn Lê Phước Thịnh
28 tháng 2 2023 lúc 22:56

2:

#include <bits/stdc++.h>

using namespace std;

int main()

{

int n,i,kt=0;

cin>>n;

for (int i=2; i*i<=n; i++)

if (n%i==0) kt=1;

if (kt==0) cout<<"YES";

else cout<<"NO";

}

Bình luận (0)