K
Khách

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 a:array[1..300]of integer;

i,n,t,tb: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 i mod 2=1 then t:=t+a[i];

tb:=0;

for i:=1 to n do 

  tb:=tb+a[i];

writeln('Tong cac phan tu cua day o vi tri le la: ',t);

writeln('Trung binh cong cua day la: ',tb/n:4:2);

readln;

end.

Bài 1: 

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 

  if a[i] mod 2<>0 then write(a[i]:4);

readln;

end.

Bài 2: 

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

  if a[i] mod 2=0 then write(a[i]:4);

readln;

end.

#include <bits/stdc++.h>

using namespace std;

long long a[1000],n,i;

int main()

{

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

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

cin>>n;

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

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

if (a[i]>0) cout<<a[i]<<" ";

return 0;

}

#include <bits/stdc++.h>

using namespace std;

long long a[10000],i,n,t;

int main()

{

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

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

cin>>n;

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

t=0;

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

cout<<fixed<<setprecision(1)<<(t*1.0)/(n*1.0);

return 0;

}

2 tháng 3 2021

Program HOC24;

var i,n,d: integer;

t: real;

function nt(b: longint): boolean;

var j: longint;

begin

nt:=true;

if (b=2) or (b=3) then exit;

nt:=false;

if (b=1) or (b mod 2=0) or (b mod 3=0) then exit;

j:=5;

while j<=trunc(sqrt(b)) do

begin

if (b mod j=0) or (b mod (j+2)=0) then exit;

j:=j+6;

end;

nt:=true;

end;

begin

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

for i:=1 to n do 

begin

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

end;

t:=0; d:=0;

for i:=1 to n do if nt(a[i]) then

begin

t:=t+a[i];

d:=d+1;

end;

write('Trung binh cong cac so nguyen to trong day: ',t/d:1:2);

readln

end.

Cách 2: 

uses crt;

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

i,n,t,dem,j,kt:integer;

begin

clrscr;

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

for i:=1 to n do 

begin

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

end;

t:=0;

dem:=0;

for i:=1 to n do 

  if a[i]>1 then 

begin

kt:=0;

for j:=2 to a[i]-1 do 

  if a[i] mod j=0 then kt:=1;

if kt=0 then 

begin

t:=t+a[i];

inc(dem);

end;

end;

writeln('Trung binh cong cac so nguyen to la: ',t/dem:4:2);

readln;

end.

7 tháng 3 2023

Bạn bổ sung đề nhé

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.

Bài 1: 

uses crt;

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

i,n,min:integer;

begin

clrscr;

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

for i:=1 to n do 

begin

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

end;

min:=a[1];

for i:=1 to n do 

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

writeln(min);

readln;

end.

Bài 2: 

uses crt;

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

i,n,max:integer;

begin

clrscr;

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

for i:=1 to n do 

begin

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

end;

max:=a[1];

for i:=1 to n do 

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

writeln(max);

readln;

end.