Những câu hỏi liên quan
Nguyễn Phan Thanh Mai
Xem chi tiết
Nguyễn Lê Phước Thịnh
13 tháng 5 2021 lúc 9:40

uses crt;

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

i,n,t1,t2,dem1,dem2:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

writeln('Day so vua nhap la: ');

for i:=1 to n do 

  write(a[i]:4);

writeln;

t1:=0;

dem1:=0;

t2:=0;

dem2:=0;

for i:=1 to n do 

 begin

if a[i] mod 2=0 then

begin

t1:=t1+a[i];

inc(dem1);

end

else begin

t2:=t2+a[i];

inc(dem2);

end;

end;

writeln('Trung binh cac so chan la: ',t1/dem1:4:2);

writeln('Trung binh cac so le la: ',t2/dem2:4:2);

readln;

end.

Bình luận (0)
HUY HUỲNH QUANG
Xem chi tiết
Kiều Vũ Linh
5 tháng 5 2023 lúc 14:54

Bài 5:

Var a:array:[1..1000] of integer;

i,n,max:integer;

sc, sl:longint;

Begin

Write('n = ');readln(n);

For i:=1 to n do

Begin

Write('Nhap so thu ',i,' = ');rreadlna[i]);

If a[i] mod 2 = 0 then sc:=sc+b[i];

If a[i] mod 2 <> 0 then sl:=sl+a[i];

End;

max:=a[1];

For i:=2 to n do

If a[i] > max then max:=a[i];

Writeln('Tong cac so chan la ',sc);

Writeln('Tong cac so le la ',sl);

write('So lon nhat la ',max);

Readln

End.

Bình luận (1)
Hiền Nguyễn
Xem chi tiết
Hiền Nguyễn
24 tháng 3 2021 lúc 9:08

Bạn ơi giúp mình với chiều nay mình thi rồi

 

Bình luận (0)
Nguyễn Lê Phước Thịnh
24 tháng 3 2021 lúc 20:16

Câu 2: 

uses crt;

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

i,n,tb:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

tb:=0;

for i:=1 to n do 

  tb:=tb+a[i];

writeln(tb/n:4:2);

readln;

end.

Bình luận (0)
hưng phạm
Xem chi tiết
Nguyễn Lê Phước Thịnh
12 tháng 4 2022 lúc 8:03

#include <bits/stdc++.h>

using namespace std;

long long a[100],i,n,t,nn;

int main()

{

cin>>n;

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

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

cout<<a[i]<<" ";

cout<<endl;

t=0;

for (i=1; i<=n; i++) if (a[i]%2==0) t+=a[i];

nn=a[1];

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

nn=min(nn,a[i]);

cout<<t<<endl;

cout<<nn<<endl;

cout<<a[1]+a[n];

return 0;

}

Bình luận (0)
Thảo Nguyên Ngô
Xem chi tiết
Nguyễn Lê Phước Thịnh
9 tháng 12 2021 lúc 23:17

a:

#include <bits/stdc++.h>

using namespace std;

long long n,i,a[10000];

int main()

{

cin>>n;

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

cin>>a[i];

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

cout<<a[i]<<" ";

return 0;

}

Bình luận (0)
Nguyễn Trần Hồng Ngọc
Xem chi tiết
Phía sau một cô gái
7 tháng 5 2023 lúc 20:02

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.

Bình luận (0)
Phan Thu
Xem chi tiết
Nhật
Xem chi tiết
Nguyễn Lê Phước Thịnh
21 tháng 3 2022 lúc 10:18

uses crt;

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

n,i,t1,t2:integer;

begin

clrscr;

readln(n);

for i:=1 to n do readln(a[i]);

for i:=1 to n do write(a[i]:4);

writeln;

for i:=1 to n do 

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

writeln;

for i:=1 to n do

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

writeln;

t1:=0;

t2:=0;

for i:=1 to n do 

  begin

if a[i] mod 2=0 then t1:=t1+a[i]

else t2:=t2+a[i];

end;

writeln(t1);

writeln(t2);

readln;

end.

Bình luận (0)
Sói Channel
Xem chi tiết
Phía sau một cô gái
18 tháng 2 2023 lúc 15:07

n = int(input('Nhập n ( n < 150): '))

if n >= 150:

     print('n phải nhỏ hơn 150')

else:

     arr = [ ]

     total = 0

     # Nhập vào dãy số nguyên

     for i in range(n):

          arr.append(int(input('Nhập phần tử thứ ' + str(i+1) + ': ')))

     # In dãy vừa nhập

     print('Dãy vừa nhập là: ', end='')

     for i in range(n):

          print(arr[i], end=' ')

     # Tính tổng các phần tử lẻ

     for i in range(n):

          if arr[i] % 2 != 0:

               total += arr[i]

     print('\nTổng các phần tử lẻ là:', total)

    

Bình luận (0)