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.

Bài 3: 

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n;

int main()

{

cin>>n;

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

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

return 0;

}

24 tháng 3 2021

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

 

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.

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.

a: 

#include <bits/stdc++.h>

using namespace std;

double a[1000];

int n,i;

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: 

#include <bits/stdc++.h>

using namespace std;

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

int main()

{

cin>>n;

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

t=0;

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

cout<<t;

return 0;

}

30 tháng 4 2022

bạn có thể nào làm cho mình phần b làm theo kiểu lớp 8 đc không chứ nhìn như này mik ko hiểu

 

10 tháng 5 2023

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

i,n,max:integer;

Begin

Write('Nhap so luong phan tu n = ');readln(n);

For i:=1 to n do

Begin

Write('Nhap diem thu ',i,' = ');readln(a[i]);

End;

Write('Cac diem vua nhap la: ');

For i:=1 to n do 

Write(a[i]:8);

writeln;

max:=a[1];

For i:=2 to n do

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

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

Readln

End.

uses crt;

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

i,n,h:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

h:=0;

for i:=1 to n do 

  if a[i] mod 2=0 then h:=h-a[i];

writeln(h);

readln;

end.

9 tháng 5 2023

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

i,n,max,min,s:real;

Begin

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

For i:=1 to n do

Begin

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

End;

max:=a[1];

min:=a[1];

For i:=2 to n do

Begin

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

If a[i] < min then min:=a[i];

End;

Write('Cac so vua nhap la ');

for i:=1 to n do write(a[i]:10:2):

Writeln;

Writeln('Tong la ',s:10:2);

Writeln('So nho nhat la ',min:10:2);

Write('So lon nhat la ',max:10:2);

Readln

End.

27 tháng 5 2023

var
  Mang: array[1..100] of Integer;
  N, i, Tong, Min, Max: Integer;

begin
  // Yêu cầu nhập độ dài của dãy số từ bàn phím
  Write('Nhap do dai cua day so: ');
  ReadLn(N);

  // Yêu cầu nhập các phần tử của dãy từ bàn phím
  for i := 1 to N do
  begin
    Write('Nhap phan tu thu ', i, ': ');
    ReadLn(Mang[i]);
  end;

  // In ra màn hình các số vừa nhập
  Write('Cac so vua nhap: ');
  for i := 1 to N do
  begin
    Write(Mang[i], ' ');
  end;
  WriteLn;

  // Tính tổng các phần tử của dãy số
  Tong := 0;
  for i := 1 to N do
  begin
    Tong := Tong + Mang[i];
  end;
  WriteLn('Tong cac phan tu cua day so la: ', Tong);

  // Tìm giá trị nhỏ nhất của dãy số
  Min := Mang[1];
  for i := 2 to N do
  begin
    if Mang[i] < Min then
      Min := Mang[i];
  end;
  WriteLn('Gia tri nho nhat cua day so la: ', Min);

  // Tìm giá trị lớn nhất của dãy số
  Max := Mang[1];
  for i := 2 to N do
  begin
    if Mang[i] > Max then
      Max := Mang[i];
  end;
  WriteLn('Gia tri lon nhat cua day so la: ', Max);

  ReadLn;
end.

7 tháng 6 2021

uses crt;
var a:array[1..1000000] of longint;
      n,i,s:longint;
begin
      clrscr;
      write('Nhap so luong phan tu: '); readln(n);
      for i:=1 to n do 
            begin
                  write('Nhap phan tu thu ',i,': '); readln(a[i]);
                  if a[i] mod 2=1 then inc(s,a[i]);
            end;
      write('Tong cac so le: ',s);
      readln;
end.