Hãy viết chương trình sắp xếp 3 số a, b, c theo chiều tăng dần. Trong đó sử dụng thủ tục hoandoi có 2 tham số truyền vào. Biết a, b, c được nhập từ bàn phím
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.
Program HOC24;
var t: longint;
a,b: integer;
function gt(x: integer): longint;
var i: integer; tich: longint;
begin
tich:=1;
for i:=1 to n tich:=tich*i;
gt:=tich;
end;
begin
write('Nhap a: '); readln(a);
write('Nhap b: '); readln(b);
t:=gt(a)+gt(b)+gt(a-b);
write('T = ',t);
readln
end.
<bits/stdc++.h>
using namespace std;
int DTT(int a, int b, int c)
int m = sqrt(2*b*b+2*c*c-a*a)/2;
return m;
int main()
int a, b, c, m;
cout << "Nhap ba canh tam giac" << endl;
cin >> a >> b >> c;
m = DTT(a,b,c);
cout << m;
return 0;
end.
uses crt;
var a,b,c:real;
{-----------------chuong-trinh-con--------------------}
function ttuyen(x,y,z:real):integer;
begin
ttuyen:=(2*(sqr(ab)+sqr(ac))-sqr(bc));
end;
{---------------chuong-trinh-chinh-----------------------}
begin
clrscr;
repeat
write('a='); readln(a);
write('b='); readln(b);
write('c='); readln(c);
until (a>0) and (b>0) and (c>0) and (a+b>c) and (a+c>b) and (b+c>a);
writeln(sqrt(ttuyen(a,b,c))/4:4:2);
readln;
end.
tham khảo:
uses crt;
var n,i:integer;
a:array[1..100] of integer;
begin
clrscr;
write(‘nhap so phan tu cua day:’);readln(n);
for i:=1 to n do
begin
write(‘a[‘,i,’]=’);readln(a[i]);
end;
writeln(‘day so da nhap:’);
for i:=1 to n do write(a[i]:2);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,a[1000];
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
sort(a+1,a+n+1);
for (i=n; i>=1; i--) cout<<a[i]<<" ";
return 0;
}
uses crt;
var a,b,c,p,s,am,bn,cp:real;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
write('Nhap c='); readln(c);
if (a>0) and (b>0) and (c>0) and (a+b>c) and (a+c>b) and (b+c>a) then
begin
writeln('Day la ba canh trong mot tam giac vuong');
p:=(a+b+c)/2;
s:=sqrt(p*(p-a)*(p-b)*(p-c));
writeln('Dien tich tam giac la: ',s:4:2);
am:=sqrt(2*(sqr(b)+sqr(c))-sqr(a))/4;
bn:=sqrt(2*(sqr(a)+sqr(c))-sqr(b))/4;
cp:=sqrt(2*(sqr(a)+sqr(b))-sqr(c))/4;
writeln('Do dai duong trung tuyen ung voi canh a la: ',am:4:2);
writeln('Do dai duong trung tuyen ung voi canh b la: ',bn:4:2);
writeln('Do dai duong trung tuyen ung voi canh c la: ',cp:4:2);
end
else writeln('Day khong la ba canh trong mot tam giac');
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
sort(a+1,a+n+1);
for (i=n; i>=1; i--) cout<<a[i]<<" ";
return 0;
}
program SapXepMang;
var
N, i, j, temp: integer;
arr: array of integer;
begin
write('Nhap N: ');
readln(N);
SetLength(arr, N);
for i := 0 to N - 1 do
begin
write('Nhap phan tu thu ', i + 1, ': ');
readln(arr[i]);
end;
for i := 0 to N - 2 do
for j := i + 1 to N - 1 do
if arr[i] < arr[j] then
begin
temp := arr[i];
arr[i] := arr[j];
arr[j] := temp;
end;
writeln('Mang da sap xep theo thu tu giam dan: ');
for i := 0 to N - 1 do
write(arr[i], ' ');
readln;
end.
Var a:array[1..1000] of integer;
i,m,tam:integer;
Begin
Write('m = ');readln(m);
For i:=1 to m do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to m do
If a[i] < a[i+1] then
Begin
tam:=a[i];
a[i]:=a[i+1];
a[i+1]:=tam;
End;
Write('Mang sau khi sap xep: ');
For i:=1 to m do
Write(a[i]:8);
Readln;
End.
uses crt;
var a,b,c:integer;
{-----------------------------chuong-trinh-con----------------------------}
procedure hoandoi(var x,y:integer);
var tam:integer;
begin
tam:=x;
x:=y;
y:=tam;
end;
{-----------------------------chuong-trinh-chinh----------------------------}
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
write('Nhap c='); readln(c);
if a>b then hoandoi(a,b)
else if b>c then hoandoi(b,c);
writeln(a,' ',b,' ',c);
readln;
end.