Bài 18: Ví dụ về cách viết và sử dụng chương trình con

Văn Huy
Xem chi tiết
Nguyễn Lê Phước Thịnh
8 tháng 5 2021 lúc 20:04

uses crt;

var xa,ya,xb,yb,xc,yc:integer;

ab,ac,bc,cv,p,s:real;

begin

clrscr;

write('Nhap toa do diem A:'); readln(xa,ya);

write('Nhap toa do diem B:'); readln(xb,yb);

write('Nhap toa do diem C:'); readln(xc,yc);

ab:=sqrt(sqr(xa-xb)+sqr(ya-yb));

ac:=sqrt(sqr(xa-xc)+sqr(ya-yc));

bc:=sqrt(sqr(xb-xc)+sqr(yb-yc));

if (ab+bc>ac) and (ab+ac>bc) and (ac+bc>ab) then

begin

cv:=ab+bc+ac;

p:=cv/2;

s:=sqrt(p*(p-ab)*(p-ac)*(p-bc));

writeln('Chu vi la: ',cv:4:2);

writeln('Dien tich la: ',dt:4:2);

kt:=0;

if (ab=ac) and (ab<>bc) and (ac<>bc) then kt:=1;

if (ac=bc) and (ac<>ab) and (bc<>ab) then kt:=1;

if (ab=bc) and (ab<>ac) and (bc<>ac) then kt:=1;

if (ab=ac) and (ac=bc) then kt:=2;

if sqr(ab)=sqr(ac)+sqr(bc) then kt:=3;

if sqr(ac)=sqr(ab)+sqr(bc) then kt:=3;

if sqr(bc)=sqr(ab)+sqr(ac) then kt:=3;

if kt=0 then writeln('Day la tam giac thuong');

if kt=1 then writeln('Day la tam giac can');

if kt=2 then writeln('Day la tam giac deu');

if kt=3 then writeln('Day la tam giac vuong');

end

else writeln('Day khong phai la toa do 3 dinh cua mot tam giac');

readln;

end.

Bình luận (0)
Hưng Cận
Xem chi tiết
Nguyễn Lê Phước Thịnh
7 tháng 5 2021 lúc 21:31

uses crt;

var x,y:integer;

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

function tong(a,b:integer):integer;

begin

tong:=a+b;

end;

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

funtion hieu(a,b:integer):integer;

begin

hieu:=a-b;

end;

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

function tich(a,b:integer):integer;

begin

tich:=a*b;

end;

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

function thuong(a,b:integer):real;

begin

thuong:=a/b;

end;

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

begin

clrscr;

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

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

writeln('Tong la: ',tong(x,y));

writeln('Hieu la: ',hieu(x,y));

writeln('Tich la: ',tich(x,y));

writeln('Thuong la: ',thuong(x,y):4:2);

readln;

end.

Bình luận (0)
Trinh Nguyễn
Xem chi tiết
Nguyễn Lê Phước Thịnh
5 tháng 5 2021 lúc 20:08

uses crt;

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

n,i,j,ucln:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

readln(a[i],b[i]);

end;

for i:=1 to n do 

  begin

if a[i]<b[i] then 

begin

ucln:=1;

for j:=1 to a[i] do

  if (a[i] mod j=0) and (b[i] mod j=0) then

begin

if ucln<j then ucln:=j;

end;

end

else begin

ucln:=1;

for j:=1 to b[i] do

  if (a[i] mod j=0) and (b[i] mod j=0) then

begin

if ucln<j then ucln:=j;

end;

end;

writeln('Uoc chung lon nhat cua cap thu ',i,' la: ',ucln);

end;

readln;

end.

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

uses crt;

var n,i,t:integer;

{----------------chuong-trinh-con-kiem-tra-so-nguyen-to----------------------}
function ktnt(x:integer):boolean;

var kt:boolean;

n,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;

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

t:=0;

for i:=2 to n do 

 if ktnt(i)=true then 

begin

write(i:4);

t:=t+i;

end;

writeln;

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

readln;

end.

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

uses crt;

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

i,n,max,min,dem,k,t1,t2,tam,j:integer;

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

procedure NHAP_mang;

begin

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

for i:=1 to n do 

 begin

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

end;

end;

{--------------chuong-trinh-con-xuat-mang---------------------}

procedure hien_mang;

begin

for i:=1 to n do

  write(a[i]:4);

end;

{------------chuong-trinh-con-tim-min--------------------}

procedure tim_min;

begin

min:=a[1];

for i:=1 to n do 

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

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

end;

{--------------chuong-trinh-con-tim-max-----------------}

procedure tim_max;

begin

max:=a[1];

for i:=1 to n do 

  if max<a[i] then max:=a[i];

writeln('So lon nhat la: ',max);

end;

{---------------------chuong-trinh-con-dem-so-k----------------------}

procedure dem_k;

begin

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

dem:=0;

for i:=1 to n do 

  if a[i]=k then inc(dem);

writeln('So phan tu bang ',k,' la: ',dem);

end;

{------------------chuong-trinh-con-tinh-tong-so-chan-------------------------}

procedure tong_chan;

begin

t1:=0;

for i:=1 to n do 

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

writeln(t1);

end;

{------------------chuong-trinh-con-tinh-tong-so-le-----------------------}

procedure tong_le;

begin

t2:=0;

for i:=1 to n do 

  if a[i] mod 2<>0 then t2:=t2+a[i];

writeln(t2);

end;

{-------------------chuong-trinh-con-sap-xep-mang-khong-giam----------------}

procedure sap_xep;

begin

for i:=1 to n-1 do 

  for j:=i+1 to n do 

if a[i]>a[j] then 

begin

tam:=a[i];

a[i]:=a[j];

a[j]:=tam;

end;

for i:=1 to n do 

  write(a[i]:4);

end;

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

begin

clrscr;

nhap_mang;

hien_mang;

tim_min;

tim_max;

dem_k;

tong_chan;

tong_le;

sap_xep;

readln;

end.

Bình luận (0)
Đồng Trung
Xem chi tiết
❄️Ꭵᑕᗴ❄️
13 tháng 4 2021 lúc 21:48

program Angus;
uses crt;
var 
    x1,x2,x3,y1,y2,y3,s,p,n,a,b,c :real;
begin
        clrscr;
        write('Nhập tọa độ điểm A(x1,y1)= '); readln(x1,y1);
        write('Nhập tọa độ điểm B(x2,y2)= '); readln(x2,y2);
        write('Nhập tọa độ điểm C(x3,y3)= '); readln(x3,y3);
a:=sqrt(sqr(x2-x1)+sqr(y2-y1));
b:=sqrt(sqr(x3-x2)+sqr(y3-y2));
c:=sqrt(sqr(x1-x3)+sqr(y1-y3));
if (a+b>c) and (b+c>a) and (c+a>b) then
        begin
                p:=a+b+c;
                n:=p/2;
                s:=sqrt(n*(n-a)*(n-b)*(n-c));
        writeln('Chu vi = ', p:0:2);
        writeln('Diện tích = ',s:0:2);
        end
else writeln('các điểm bạn vừa nhập không tạo thành 1 tam giác :> ');
readln

Bình luận (0)
No One Actually
Xem chi tiết
No One Actually
11 tháng 4 2021 lúc 20:11

help

 

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

const fi='input.txt'

fo='output.txt'

var f1,f2:text;

a,b,c,max:real;

begin

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

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

readln(f1,a,b,c);

min:=a;

if min>b then min:=b;

if min>c then min:=c;

writeln(f2,min);

close(f1);

close(f2);

end.

Bình luận (0)
Vy Tường
Xem chi tiết
Bùi Anh Tuấn
28 tháng 3 2021 lúc 20:21

Bình luận (0)
★゚°☆ Trung_Phan☆° ゚★
28 tháng 3 2021 lúc 20:25

theo C++ nhé bạn

#include<bits/stdc++.h>

using namespace std;

int a[100],n,i;

int main()

{

cout<<"hay nhap so phan tu cua mang: ";     

cin>>n;

cout<<"hay nhap gia tri cac phan tu cua mang: ";   

for(i=1;i<=n;i++) cin>>a[i];

cout<<"gia tri cac phan tu trong mang la: ";

 for(i=1;i<=n;i++) cout<<a[i]<<" ";

return 0;

}

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

uses crt;

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

i,n:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

for i:=1 to n do 

  write(a[i]:4);

readln;

end.

Bình luận (0)
Vy Tường
Xem chi tiết
nguyễn an phát
28 tháng 3 2021 lúc 19:40

program mang;

uses crt;

var n,i:integer;

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

begin

clrscr;

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

for i:=1 to n do

begin

write('nhap phan tu a[',i,']:');readln(n);

end;

for i:=1 to n do

write(a[i]:3);

readln;

end.

Bình luận (0)
Bùi Anh Tuấn
28 tháng 3 2021 lúc 19:41

Bình luận (0)
Nguyễn Lê Phước Thịnh
28 tháng 3 2021 lúc 20:29

uses crt;

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

i,n:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

for i:=1 to n do 

  write(a[i]:4);

readln;

end.

Bình luận (0)
Đoàn Vĩ Khang
Xem chi tiết
Nguyễn Lê Phước Thịnh
22 tháng 3 2021 lúc 21:29

uses crt;

var a,b:integer;

{-------------chuong-trinh-con-tinh-tong---------------------}

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

begin

tong:=x+y;

end;

{-------------chuong-trinh-con-tinh-tich------------------}

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

begin

tich:=x*y;

end;

{-----------------chuong-trinh-con-so-lon------------------}

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

begin

if x>y then solon:=x

else solon:=y;

end;

{-----------------chuong-trinh-con-so-be------------------}

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

begin

if x<y then sobe:=x

else sobe:=y;

end;

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

begin

clrscr;

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

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

writeln('Tong la: ',tong(a,b));

writeln('Tich la: ',tich(a,b));

writeln('So lon la: ',solon(a,b));

writeln('So be la: ',sobe(a,b));

readln;

end.

Bình luận (0)