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.

13 tháng 2 2017

Bạn ơi! Mình viết code thôi, vì chưa có thời gian nên mình chưa test lại, bạn test lại giúp mình, nếu sai thì báo mình nha! (Bạn cố sữa lỗi trước nhé!)ok

program abc;

uses crt;

var

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

i, n, d, d2, d5: integer;

begin

clrscr;

write ('Nhap n: ');

readln (n);

for i:=1 to n do

begin

write ('Nhap so thu ', i, ': ');

readln (a[i]);

end;

d:=0; d2:=0; d5:=0;

for i:=1 to n do

begin

if a[i] <0 then d:=d+1;

if a[i] mod 2 = 0 then d2:=d2+1;

if a[i] mod 5 = 0 then d5:=d5+1;

end;

writeln ('Co ', d, ' so am trong mang.');

writeln ('Co ', d2, ' so chia het cho 2.');

writeln ('Co ', d5, ' so chia het cho 5.');

writeln;

writeln ('Nhan Enter de ket thuc chuong trinh!');

readln;

end.

16 tháng 2 2017

in ra các số chia hết cho 2 và 5

uses crt;

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

i,n,dem:integer;

begin

clrscr;

readln(n);

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

dem:=0;

for i:=1 to n do  

if trunc(sqrt(a[i]))=sqrt(a[i]) then inc(dem);

writeln(dem);

readln;

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.

uses crt;

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

i,n,dem,t:integer;

begin

clrscr;

repeat

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

until (0<n) and (n<=1000);

for i:=1 to n do 

begin

repeat

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

until abs(a[i])<=1000;

end;

for i:=1 to n do 

  write(a[i]:4);

writeln;

dem:=0;

for i:=1 to n do 

  if a[i]=0 then inc(dem);

writeln('So phan tu bang 0 la: ',dem);

t:=0;

for i:=1 to n do 

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

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

readln;

end. 

uses crt;

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

i,n,dem,dem1,dem2,t:integer;

s:real;

begin

clrscr;

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

for i:=1 to n do 

begin

repeat

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

until a[i]>0;

end;

for i:=1 to n do 

  write(a[i]:4);

writeln;

dem:=0;

for i:=1 to n do

  if a[i]>10 then inc(dem);

writeln('So phan tu lon hon 10 la: ',dem);

dem1:=0;

dem2:=0;

for i:=1 to n do 

begin

if a[i] mod 2=0 then inc(dem1)

else inc(dem2);

end;

writeln('So luong so chan la: ',dem1);

writeln('So luong so le la: ',dem2);

t:=0;

s:=1;

for i:=1 to n do 

  begin

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

if (i mod 2=1) and (a[i] mod 2=0) then s:=s*a[i];

end;

writeln('Tong cac so o vi tri chan co gia tri le la: ',t);

writeln('Tich cac so o vi tri le co gia tri chan la: ',s:4:2);

writeln('Cac so le la: ');

for i:=1 to n do 

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

writeln;

writeln('Cac so chan va lon hon 10 la: ');

for i:=1 to n do 

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

readln;

end.

18 tháng 2 2021

Thank you

22 tháng 3 2022

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

      i,n,S,d:byte;

 begin

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

  for i:=1 to n do begin

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

                           readln(A[i]);

                          end;

d:=0; S:=0;

for i:=1 to n do if A[i] mod 2 = 0 then begin

                                                          d:=d+1;

                                                           S:=S+A[i];

                                                           end;

write('Dãy có ',d,' phần tử là số chẵn và tổng của chúng là : S = ',S);

readln

end.

                                                          

                      

  

11 tháng 3 2023

n = int(input("Nhập số phần tử của mảng: "))

arr = []

for i in range(n):

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

even_arr = []

odd_arr = []

for num in arr:

     if num % 2 == 0:

          even_arr.append(num)

     else:

          odd_arr.append(num)

new_arr = even_arr + odd_arr

print("Mảng mới: ", new_arr)

Bài 2: 

#include <bits/stdc++.h>

using namespace std;

string st;

int d;

int main()

{

getline(cin,st);

d=st.length();

cout<<d;

return 0;

}

19 tháng 1 2022

Bài 1:

Var so,i,n,dem:integer;

Begin

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

For i:=1 to n do

Begin

Write('Nhap so thu ',i);readln(so);

If so mod 2 = 0 then dem:=dem+1;

End;

Write('Co ',dem,' so chan');

Readln;

End.

Bài 2:

Var st:string;

Begin

Write('Nhap vao xau ki tu ');readln(st);

Write(' Xau vua nhap co do dai la ',length(st));

Readln;

End.

uses crt;

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

i,n,dem:integer;

begin

clrscr;

readln(n);

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

dem:=0;

for i:=1 to n do 

  if (trunc(sqrt(a[i]))=sqrt(a[i]) then dem:=dem+1;

writeln(dem);

readln;

end.

14 tháng 4 2023

# Nhập mảng A từ bàn phím
n = int(input("Nhập số lượng phần tử của mảng A: "))
A = []
for i in range(n):
    A.append(int(input("Nhập phần tử thứ {} của mảng A: ".format(i+1))))

# Tính trung bình cộng các phần tử chia hết cho 3 và 5
sum_35 = 0
count_35 = 0
for num in A:
    if num % 3 == 0 and num % 5 == 0:
        sum_35 += num
        count_35 += 1
if count_35 > 0:
    tb_35 = sum_35 / count_35
    print("Trung bình cộng các phần tử chia hết cho 3 và 5 trong mảng A là:", tb_35)
else:
    print("Không có phần tử nào chia hết cho cả 3 và 5 trong mảng A")

# In ra các phần tử chia hết cho M và tính tổng các phần tử chia hết cho M
M = int(input("Nhập giá trị M: "))
sum_M = 0
count_M = 0
for num in A:
    if num % M == 0:
        print(num, end=" ")
        sum_M += num
        count_M += 1
print("\nTổng các phần tử chia hết cho M trong mảng A là:", sum_M)