Những câu hỏi liên quan
Phan Thị Thùy Ngân
Xem chi tiết
Nguyễn Lê Phước Thịnh
2 tháng 5 2021 lúc 22:29

Câu 2: 

uses crt;

var a,b:integer;

{-----------------chuong-trinh-con-------------------}

function ucln(x,y:integer):integer;

var i,uc:integer;

begin

if x<y then 

begin

uc:=1;

for i:=1 to x do 

  if (x mod i=0) and (y mod i=0) then  

begin

if uc<i then uc:=i;

end;

end

else begin

uc:=1;

for i:=1 to y do 

  if (x mod i=0) and (y mod i=0) then  

begin

if uc<i then uc:=i;

end;

end;

ucln:=uc;

end;

{--------------------------chuong-trinh-chinh------------------------}

begin

clrscr;

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

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

writeln(a,'/',b,'=',a div ucln(a,b),'/',b div ucln(a,b));

readln;

end.

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

Câu 1: 

const fi='songuyen.inp'

fo='tong.out'

var f1,f2:text;

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

i,n,t:integer;

begin

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

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

n:=0;

while not eoln(f1) do 

  begin

n:=n+1;

read(f1,a[n]);

end;

t:=0;

for i:=1 to n do 

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

writeln(f2,t);

close(f1);

close(f2);

end.

Bình luận (0)
Huyền Trang
Xem chi tiết
Dư Dư
Xem chi tiết
Nguyễn Lê Phước Thịnh
8 tháng 3 2022 lúc 7:19

uses crt;

const fi='kq.txt'

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

i,n:integer;

f1:text;

begin

clrscr;

n:=10;

for i:=1 to n do readln(a[i]);

assign(f1,fi); rewrite(f1);

for i:=1 to n do 

  begin

if (n%5<>0) then write(f1,a[i]:4);

else writeln(f1);

end;

close(f1);

readln;

end.

Bình luận (0)
Kiệt Bùi
Xem chi tiết
Lâm Khả Doanh
Xem chi tiết
Nguyễn Lê Phước Thịnh
28 tháng 2 2023 lúc 22:28

1:

uses crt;

var n,i,t:integer;

begin

clrscr;

readln(n);

t:=0;

for i:=1 to n do

t:=t+i*i;

write(t);

readln;

end.

Bình luận (0)
Lê Chiêu Nguyên	Vũ
4 tháng 4 2023 lúc 10:21

2

program bt2;

var i,n,t:integer;

begin

readln(n);

s:=0;

for i:=1 to n do

if i mod 2 = 1 then s:=s+i;

readln;

end.

Bình luận (0)
lân đinh
Xem chi tiết
Nguyễn Lê Phước Thịnh
11 tháng 5 2021 lúc 10:50

Bài 3:

uses crt;

var i:integer;

{------------------chuong-trinh-con-kiem-tra-so-nguyen-to----------------------}

function ktnt(x:integer):boolean;

var kt:boolean;

i:integer;

begin

kt:=true;

for i:=2 to x-1 do

  if x mod i=0 then kt:=false;

if kt=true then ktnt:=true

else ktnt:=false;

end;

{-------------------------chuong-trinh-chinh----------------------------}

begin

clrscr;

for i:=2 to 9999 do 

  if (ktnt(i)=true) and (ktnt(i+2)=true) then 

begin

writeln(i,',',i+2);

delay(500);

end;

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
11 tháng 5 2021 lúc 10:56

Bài 4: 

uses crt;

var a,b,c,kt:integer;

begin

clrscr;

write('Nhap ngay:'); readln(a);

write('Nhap thang:'); readln(b);

write('Nhap nam:'); readln(c);

kt:=0;

if (b=1) and (0<a) and (a<=31) then kt:=1;

if (b=2) and (0<a) and (a<=28) then kt:=1;

if (b=2) and (0<a) and (a<=29) and (c mod 4=0) then kt:=1;

if (b=3) and (0<a) and (a<=31) then kt:=1;

if (b=4) and (0<a) and (a<=30) then kt:=1;

if (b=5) and (0<a) and (a<=31) then kt:=1;

if (b=6) and (0<a) and (a<=30) then kt:=1;

if (b=7) and (0<a) and (a<=31) then kt:=1;

if (b=8) and (0<a) and (a<=31) then kt:=1;

if (b=9) and (0<a) and (a<=30) then kt:=1;

if (b=10) and (0<a) and (a<=31) then kt:=1;

if (b=11) and (0<a) and (a<=30) then kt:=1;

if (b=12) and (0<a) and (a<=31) then kt:=1;

if kt=0 then writeln('Khong hop le')

else writeln('Hop le');

readln;

end.

Bình luận (0)
Lê Thị Cẩm Tiên
9 tháng 7 2021 lúc 10:30

Bạn ơi bạn làm ra bài 3 chưa, cho mình xin cách làm nữa.

Python

Bình luận (0)
hoàng phúc nguyễn
Xem chi tiết
Nguyễn Lê Phước Thịnh
22 tháng 2 2022 lúc 21:37

Câu 1: 

#include <bits/stdc++.h>

using namespace std;

long long i,n,k,dem,x;

int main()

{

cin>>n;

cin>>k;

dem=0;

for (i=1; i<=n; i++)

{

cin>>x;

if (x==k) dem++;

}

cout<<dem;

return 0;

}

Bình luận (0)
Ngọc Hồng
Xem chi tiết
Nguyễn Lê Phước Thịnh
17 tháng 3 2022 lúc 14:48

#include <bits/stdc++.h>

using namespace std;

string st;

int d,i,dem;

int main()

{

freopen("xau.inp","r",stdin);

freopen("xau.out","w",stdout);

cin>>st;

d=st.length();

dem=0;

for (i=0; i<=d-1; i++)

if (st[i]=='a') dem++;

cout<<dem;

return 0;

}

Bình luận (0)
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)