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.
uses crt;
var n,i,t,dem,t1,dem1,t2:longint;
a:array[1..100]of longint;
tbc,tbca,tbcd:real;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{--------------------cau-1-----------------------}
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('tong cac phan tu cua day la: ',t);
{-------------------cau-2-------------------------}
dem:=0;
t1:=0;
for i:=1 to n do
if a[i]>0 then
begin
dem:=dem+1;
t1:=t1+a[i];
end;
writeln('so luong cac so hang duong la: ',dem);
writeln('tong cua cac so hang duong la: ',t1);
{-------------------cau-3-------------------------}
dem1:=0;
t2:=0;
for i:=1 to n do
if a[i]<0 then
begin
inc(dem1);
t2:=t2+a[i];
end;
writeln('so luong cac so hang am la: ',dem1);
writeln('tong cua cac so hang am la: ',t2);
{-------------------cau-4-----------------------}
tbc:=t/n;
writeln('trung binh cong cua day so la: ',tbc:4:2);
tbcd:=t1/dem;
writeln('trung binh cong cua cac phan tu duong la: ',tbcd:4:2);
tbca:=t2/dem1;
writeln('trung binh cong cua cac phan tu am la: ',tbca:4:2);
readln;
end.
program an_danh;
uses crt;
var n,i,nd,na:integer;
tbc,tbcd,tbca:real;
tong,tongd,tonga:longint;
a:array [1..10] of integer;
begin
clrscr;
write('So phan tu cua day so: ');readln(n);
for i:= 1 to n do
begin
write('Phan tu thu ',i,': ');
readln(a[i]);
end;
tong:= 0;
for i:= 1 to n do tong:= tong + a[i];
tbc:= tong / n;
writeln('Tong cac phan tu la: ',tong);
nd:= 0; tongd:= 0;
for i:= 1 to n do
if a[i] mod 2 = 0 then
begin
nd:= nd + 1;
tongd:= tongd + a[i];
end;
tbcd:= tongd / nd;
writeln('So cac phan tu duong trong day: ',nd);
writeln('Tong cac phan tu duong trong day: ',tongd);
na:= 0; tonga:= 0;
for i:= 1 to n do
if a[i] mod 2 <> 0 then
begin
na:= na + 1;
tonga:= tonga + a[i];
end;
tbca:= tonga / na;
writeln('So cac phan tu am trong day: ',na);
writeln('Tong cac phan tu am trong day: ',tonga);
writeln('Trung binh cong cua ca day: ',tbc:0:2);
writeln('Trung binh cong cac phan tu duong: ',tbcd:0:2);
write('Trung binh cong cac phan tu am: ',tbca:0:2);
readln
end.
b: #include <bits/stdc++.h>
using namespace std;
long long b[1000],i,n;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
cin>>b[i];
sort(b+1,b+n+1);
for (i=1; i<=n; i++)
cout<<b[i]<<" ";
return 0;
}
Câu 7:
const fi='dayso.inp';
fo='dayso.out';
var f1,f2:text;
a,b:array[1..100]of integer;
i,n,dem,j,t,kt,dem1:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,'Tong cua day so la: ',t);
b[1]:=a[1];
dem:=1;
for i:=1 to n do
begin
kt:=0;
for j:=1 to dem do
if a[i]=b[j] then kt:=1;
if kt=0 then
begin
inc(dem);
b[dem]:=a[i];
end;
end;
for i:=1 to dem do
begin
dem1:=0;
for j:=1 to n do
if b[i]=a[j] then inc(dem1);
writeln(f2,b[i],' xuat hien ',dem1,' lan');
close(f1);
close(f2);
end.
Program FNG;
Uses crt;Var A: array[1..1000] of longint; n,i,s,da,sa: longint;Begin Clrscr; Write('Nhap n: '); Readln(n); s:=0; da:=0; sa:=0; For i:=1 to n do Begin Write('A[',i,'] = '); Readln(A[i]); s:=s+A[i]; If A[i]<0 then Begin inc(da); sa:=sa+A[i]; End; End; Writeln('S = ',s); Writeln('Dem am = ',da) Write('Tong am = ',sa); ReadlnEnd.
Bai 2:
uses crt;
var a:array[1..100]of integer;
i,n,t,nn:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
nn:=a[1];
for i:=1 to n do
if nn>a[i] then nn:=a[i];
write(nn);
readln;
end.
program bai1;
uses crt;
var i,j,d:integer;
a:array[1..100]of real;
t,k:real;
begin
clrscr;
i:=1;
while 1/i>0.0321 do
begin
a[i]:=1/i;
inc(i);
d:=i;
end;
writeln('mang tren co ',d,' so hang');
i:=1;
while t+a[i]<=3 do
begin
t:=t+a[i];
inc(i);
end;
writeln('so can tim la: ',a[i+1]:5:4);
writeln(a[i+1]:5:4,' la so hang thu ',i+1);
write('nhap k:');readln(k);
for i:=1 to d do
if (k>a[i])and(k<a[i-1]) then writeln(k:5:4,' nam giua ',a[i]:5:4,' va ',a[i-1]:5:4);
readln;
end.
program bai1;
uses crt;
var i,j,d:integer;
a:array[1..100]of real;
t,k:real;
begin
clrscr;
i:=1;
while 1/i>0.0321 do
begin
a[i]:=1/i;
inc(i);
d:=i;
end;
writeln('mang tren co ',d,' so hang');
i:=1;
while t+a[i]<=3 do
begin
t:=t+a[i];
inc(i);
end;
writeln('so can tim la: ',a[i+1]:5:4);
writeln(a[i+1]:5:4,' la so hang thu ',i+1);
write('nhap k:');readln(k);
for i:=1 to d do
if (k>a[i])and(k<a[i-1]) then writeln(k:5:4,' nam giua ',a[i]:5:4,' va ',a[i-1]:5:4);
readln;
end.
uses crt;
var a:array[1..10]of integer;
i,t:integer;
begin
for i:=1 to 10 do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to 10 do
t:=t+a[i];
writeln('Tong cua day la: ',t);
writeln('Trung binh cong cua day la: ',t/n:4:2);
readln;
end.
uses crt;
var i,n,tcd,t,t1,dem,dem1,dem2,dem3,dem4,dem5:longint;
a,b,c:array[1..100]of longint;
min,max:int64;
tbc,tbcd,tbca:real;
begin
clrscr;
write('nhap n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{---------------------------cau-1----------------------}
tcd:=0;
for i:=1 to n do
tcd:=tcd+a[i];
writeln('tong cac phan tu trong day la: ',tcd);
{-------------------------cau-2----------------------}
dem:=0;
t:=0;
for i:=1 to n do
if a[i]>0 then
begin
inc(dem);
t:=t+a[i];
end;
writeln('so luong cac so hang duong la: ',dem);
writeln('tong cac so hang duong la: ',t);
{-----------------------cau-3-----------------------}
dem1:=0;
t1:=0;
for i:=1 to n do
if a[i]<0 then
begin
inc(dem1);
t1:=t1+a[i];
end;
writeln('so luong cac so hang am la: ',dem1);
writeln('tong cac so hang am la: ',t1);
{---------------------cau-4---------------------------}
tbc:=tcd/n;
tbcd:=t/dem;
tbca:=t1/dem1;
writeln('trung binh cong cua ca day la: ',tbc:4:2);
writeln('trung binh cong cua cac so duong la: ',tbcd:4:2);
writeln('trung binh cong cua cac so am la: ',tbca:4:2);
{--------------------cau-5--------------------------------}
max:=0;
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('so lon nhat cua day la: ',max);
writeln('chi so cua no la: ');
dem2:=0;
for i:=1 to n do
if max=a[i] then
begin
inc(dem2);
b[dem2]:=i;
end;
for i:=1 to dem2 do
write(b[i]:4);
{---------------------cau-6-----------------------------}
writeln;
min:=maxint;
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('so nho nhat cua day la: ',min);
writeln('chi so cua no la: ');
dem3:=0;
for i:=1 to n do
if min=a[i] then
begin
inc(dem3);
c[dem3]:=i;
end;
for i:=1 to dem3 do
write(c[i]:4);
{-------------------------cau-7------------------------}
writeln;
dem4:=0;
dem5:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then inc(dem4);
if a[i] mod 2=1 then inc(dem5);
end;
writeln('so luong so chan cua day la: ',dem4);
writeln('so luong so le cua day la: ',dem5);
readln;
end.