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.

2 tháng 3 2023

N = int(input('Nhập số dương N (N <= 200): '))

A = [ ]

# Nhập dãy A

for i in range(N):

     A.append(int(input('Nhập số nguyên thứ {}: '.format(i + 1))))

# Tính tổng và trung bình cộng

total = 0

for num in A:

     total += num

mean = total / N

print('Tổng các số trong dãy A là: {}'.format(total))

print('Trung bình cộng của dãy A là: {:.2f}'.format(mean))

2 tháng 3 2023

sao tui ko đọc dc v sos

 

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.

30 tháng 12 2021

#include <bits/stdc++.h>

using namespace std;

long long n,i,t,dem;

int main()

{

cin>>n;

t=0;

dem=0;

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

if (i%3==0)

{

t=t+i;

dem++;

}

cout<<t<<endl;

cout<<fixed<<setprecision(2)<<(t*1.0)/(dem*1.0);

return 0;

}

25 tháng 3 2021

Mọi người giúp e với ạ

 

 

uses crt;

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

i,n,tb,dem:integer;

begin

clrscr;

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

for i:=1 to n do 

begin

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

end;

tb:=0;

dem:=0;

for i:=1 to n do 

  if a[i] mod 3=0 then

begin

tb:=tb+a[i];

inc(dem);

end;

writeln('Trung binh cong cac so chia het cho 3 la: ',tb/dem:4:2);

readln;

end.

#include <bits/stdc++.h>

using namespace std;

double b[100],x,ln,t;

int i,n,dem;

int main()

{

cin>>n;

ln=-1e10;

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

{

cin>>b[i];

ln=max(ln,b[i]);

}

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

cout<<b[i]<<" ";

cout<<endl;

cout<<ln<<endl;

t=0;

dem=0;

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

if (a[i]>x) 

{

t=t+a[i];

dem++;

}

cout<<fixed<<setprecision(2)<<t/(dem*1.0);

return 0;

}

7 tháng 5 2023

program TinhTBCTimSoNT;

var
  ten, lop: string;
  n, i, tong, dem: integer;
  A: array [1..11] of integer;
  trung_binh: real;

function LaSoNguyenTo(x: integer): boolean;
var
  i: integer;
begin
  if x < 2 then
    LaSoNguyenTo := false
  else if x = 2 then
    LaSoNguyenTo := true
  else if x mod 2 = 0 then
    LaSoNguyenTo := false
  else
  begin
    i := 3;
    while (i <= trunc(sqrt(x))) and (x mod i <> 0) do
      i := i + 2;
    LaSoNguyenTo := x mod i <> 0;
  end;
end;

begin
  // Nhập tên và lớp của học sinh
  write('Nhập tên của học sinh: ');
  readln(ten);
  write('Nhập lớp: ');
  readln(lop);

  // Nhập dãy số nguyên và tính trung bình cộng
  repeat
    write('Nhập số phần tử của dãy số (n<12): ');
    readln(n);
  until n < 12;
  tong := 0;
  for i := 1 to n do
  begin
    write('Nhập phần tử thứ ', i, ': ');
    readln(A[i]);
    tong := tong + A[i];
  end;
  trung_binh := tong / n;

  // In tên, lớp, dãy số và trung bình cộng ra màn hình
  writeln('Học sinh: ', ten);
  writeln('Lớp: ', lop);
  write('Dãy số: ');
  for i := 1 to n do
    write(A[i], ' ');
  writeln;
 
  // In các số nguyên tố của dãy số ra màn hình
  writeln('Các số nguyên tố của dãy số:');
  for i := 1 to n do
    if LaSoNguyenTo(A[i]) then
      writeln(A[i]);
end.

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n,t,dem;

int main()

{

cin>>n;

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

t=0;

dem=0;

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

if ((a[i]>0) and (i%2==1))

{

t+=a[i];

dem++;

}

cout<<fixed<<setprecision(2)<<(t*1.0)/(dem*1.0);

return 0;

}

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.

26 tháng 3 2022

var a:Array [1..100] of word;

      n,i:byte;

      S:word;

begin

 write('Nhap so so hang trong day : n = '); readln(n);

 for i:=1 to n do begin

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

                          readln(A[i]);

                         end;

S:=0;

for i:=1 to n do if A[i] mod 2 = 1 then S:=S+A[i];

if S = 0 then write('Trong day khong co so le nao nen khong tong khong ton tai') else write('Tong cac so le trong day la : S = ',S);

readln

end.