Những câu hỏi liên quan
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)
Phạm Tuấn Kiệt
Xem chi tiết
Minh Lệ
2 tháng 5 2023 lúc 21:09

Program HOC24;

var d,i,n: integer;

t: real;

begin

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

for i:=1 to n do 

begin

write('Nhap so thu ',i,': '); readln(a[i]);

end;

d:=0; t:=0;

for i:=1 to n do

if a[i] mod 2=0 then 

begin

d:=d+1;

t:=t+a[i];

end;

t:=t/d;

writeln('Co ',d,' so chan trong mang');

writeln('Trung binh cong cac phan tu chan la: ',t:2:5);

write('Cac phan tu trong day theo chieu doc: ');

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

readln

end.

Bình luận (0)
minh dương
Xem chi tiết
Bình000
Xem chi tiết
Bình000
Xem chi tiết
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)
Quân Đoàn Long Tường
Xem chi tiết
Thành Phạm
26 tháng 4 2023 lúc 10:20

Python:
n = input("Nhập dãy số nguyên: ").split()
n = [int(i) for i in n]

so_le = [i for i in n if i % 2 != 0]
tong = sum(n)

print("Các số lẻ trong dãy là: ", so_le)
print("Tổng các số trong dãy là: ", tong)

Pascal:

program tongvasole;

const
  MAX_SIZE = 1000;

var
  numbers: array[1..MAX_SIZE] of Integer;
  count, i: Integer;
  total: Integer;
begin
  Write('Nhập số lượng phần tử trong dãy: ');
  ReadLn(count);
  for i := 1 to count do
  begin
    Write('Nhập phần tử thứ ', i, ': ');
    ReadLn(numbers[i]);
  end;

  Write('Các số lẻ trong dãy là: ');
  total := 0;
  for i := 1 to count do
  begin
    if numbers[i] mod 2 <> 0 then
      Write(numbers[i], ' ');
    total := total + numbers[i];
  end;
  WriteLn;

  WriteLn('Tổng các số trong dãy là: ', total);
end.

Bình luận (0)
Tuoi tom May
Xem chi tiết
Uyên
Xem chi tiết
DinoNguyen
11 tháng 5 2022 lúc 11:46

làm trên microsoft hay pascal z :?

Bình luận (0)
Nguyễn Lê Phước Thịnh
11 tháng 5 2022 lúc 13:12

uses crt;

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

i,n,t: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;

t:=0;

for i:=1 to n do t:=t+a[i];

writeln(t);

writeln(t/n:4:2);

readln;

end.

Bình luận (0)