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.

23 tháng 12 2020

uses crt;

var n,i,t:integer;

begin

clrscr;

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

t:=0;

for i:=1 to n do 

  if i mod 2=0 then t:=t+i;

writeln('Tong cac so chan trong khoang tu 1 toi ',n,' la: ',t);

readln;

end.

uses crt;

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

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

  write(a[i]:4);

writeln;

t:=0;

for i:=1 to n do 

  if a[i] mod 7=0 then t:=t+a[i];

writeln('Tong cac so chia het cho 7 la: ',t);

readln;

end. 

26 tháng 4 2023

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.

12 tháng 5 2021

program nhap_tinhtong;

uses crt;

type kmang=array[1..1000] of integer;

var A:kmang;

     n:integer;

{---Nhap---}

procedure nhap;

var i:integer;

begin

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

       for i:=1 to n do

              begin

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

              end;

end;

{---Tinh-tong---}

function tinh_tong(A:kmang; n:integer):integer;

var t,i:integer;

begin

       t:=0;

       for i:=1 to n do

              t:=t+A[i];

       tinh_tong:=t;

end;

{---CT-chinh---}

BEGIN

       clrscr;

       nhap;

       write('Tong cac phan tu la: ',tinh_tong(A,n));

       readln;

end.

12 tháng 5 2021

program nhap_tinhtong;

uses crt;

type kmang=array[1..1000] of integer;

var A:kmang;

     n:integer;

{---Nhap---}

procedure nhap;

var i:integer;

begin

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

       for i:=1 to n do

              begin

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

              end;

end;

{---Tinh-tong---}

function tinh_tong(A:kmang; n:integer):integer;

var t,i:integer;

begin

       t:=0;

       for i:=1 to n do

              t:=t+A[i];

       tinh_tong:=t;

end;

{---CT-chinh---}

BEGIN

       clrscr;

       nhap;

       write('Tong cac phan tu la: ',tinh_tong(A,n));

       readln;

end.

uses crt;

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

n,i,k,t,t1:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

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

t:=0;

for i:=1 to n do 

  if a[i] mod 2<>0 then t:=t+a[i];

t1:=0;

for i:=1 to n do 

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

writeln('Tong cac phan tu le la: ',t);

writeln('Tong cac phan tu la boi cua ',k,' la: ',t1);

readln;

end.

18 tháng 12 2021

Câu 3: Nhập một mảng gồm N phần tử.

A, tính tổng chẵn, tổng lẻ của các phấn tử trong mảng.

B, Tìm phần tử lớn nhất, nhỏ nhất trong mảng.

C, Tìm kiếm xem phần tử K nào đó có tồn tại trong mảng hay không?

 

 

Mình chỉ viết chương trình chính thôi, còn chương trình con bạn tự viết nhé

uses crt;

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

i,n,t,t1,t2:integer;

begin

clrscr;

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

for i:=1 to n do 

 begin

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

edn;

t:=0;

for i:=1 to n do 

 t:=t+a[i];

writeln(t);

readln;

end.

25 tháng 7 2021

cau 1:

uses crt;

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

n,i,min: integer;

begin

readln(n);

for i:=1 to n do

readln(a[i]);

min:=a[1];

for i:=2 to n do

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

writeln(a[i]);

readln;

end.

cau 2:

uses crt;

g:text;

s:string;

const fo='CHUSO.TXT';

begin

assign(g,fo);

rewrite(g);

readln(s);

for i:=1 to length(s) do

if not((s[i] in ['a'..'z'])and(s[i] in ['A'..'Z])) then delete(s,i,1);

writeln(g,s);

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.

Bài 1: 

uses crt;

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

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

writeln('Tong cac so chia het cho 5 la: ',t);

readln;

end.

Bài 2: 

uses crt;

var st:string;

d,i:integer;

begin

clrscr;

write('Nhap xau:'); readln(st);

d:=length(st);

for i:=1 to d do 

  if st[i]=#32 then delete(st,i,1);

writeln(st);

readln;

end.

20 tháng 12 2021

#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;

}