1. VTC cho phép nhập n số và in theo thứ tự nhập lại
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.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,tam,j: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-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);
readln;
end.
Trả lời:
Uses Crt; Var a, b, kq: Real; Pt: Char;
BEGIN
Clrscr;
Write ('a ='); Readln(a);
Write ('b ='); Readln(b);
Write ('Phep tinh can thuc hien la (+ - * /): ');
Readln(Pt);
If Pt = '+’ Then kq := a + b;
If Pt = '-’ Then kq := a - b;
If Pt = '*’ Then kq := a * b;
If Pt = '/’ Then kq := a / b;
Write (a, pt, b, '=', kq);
Readln;
END.
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:=n downto 1 do
write(a[i]:4);
readln;
end.
program oken;
uses crt;
var a: array [1..100] of intger;
i,n:integer;
begin
clrscr;
write('nhap so phan tu cua mag: '); readln(n);
for i:=1 to n do
begin
write('a[',i']: '); readln(a[i]);
end;
writeln('mang theo thu tu nguoc lai');
for i:=n downto 1 do
write(a[i],' ');
readln;
end.
Câu 1:
Program HOC24;
var a: array[1..1000] of integer;
i,n: integer; tbc: real;
begin
write('Nhap so phan tu trong mang: '); readln(n);
for i:=1 to n do
begin
write('Nhap phan tu thu ',i,' : '); readln(a[i]);
end;
tbc:=0;
for i:=1 to n do tbc:=tbc+a[i];
tbc:=tbc/n;
write('Trung binh cong la: ',tbc:6:2);
readln
end.
Câu 2:
Program HOC24;
var a: array[1..1000] of integer;
i,n,h,tg: integer;
begin
write('Nhap so phan tu trong mang: '); readln(n);
for i:=1 to n do
begin
write('Nhap phan tu thu ',i,' : '); readln(a[i]);
end;
for i:=1 to n do
for j:=i to n do
if a[i]>a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
write('Mang sau khi sap xep la: ');
for i:=1 to n do write(a[i].' ');
readln
end.
1)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] > a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep tang dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
2)
Var array:[1..1000] of integer;
i,n,t:integer;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap so thu ',i,' = ');readln(a[i]);
End;
For i:=1 to n do
If a[i] < a[i+1] then
Begin
t:=a[i];
a[i]:=a[i+1];
a[i+1]:=t;
End;
Write('Sap xep giam dan ');
For i:=1 to n do write(a[i]:8);
Readln
End.
uses crt;
var a:array[1..250] of integer;
i,n,s,t:integer;
begin
write('nhap n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
writeln('thu tu nguoc lai cua thu tu nhap la:');
for i:=n downto 1 do writeln('a[',i,']=',a[i],' ');
s:=0; t:=0;
for i:=1 to n do if a[i] mod 3=0 then s:=s+a[i]*a[i];
for i:=1 to n do if a[i] mod 5=0 then t:=t+a[i]*a[i];
writeln('tong binh phuong cac so chia het cho 3 la:',s);
write('tong binh phuong cac so chia het cho 5 la:',t);
readln
end.
#include <bits/stdc++.h>
using namespace std;
int A[1000],n,i;
int main()
{
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
sort(A+1,A+n+1);
for (int i=1; i<=n; i++)
cout<<A[i]<<" ";
cout<<endl;
for (int i=2; i<=n; i++)
cout<<A[i]-A[i-1]<<endl;
return 0;
}