Viết thuật toán , cho dãy A gồm N số nguyên A1,A2....An
Câu 1: Đếm số lượng số âm trong dãy A
Câu 2: Tính tổng các số lẻ có trong A Câu 3: Đưa ra vị trí các số chẵn trong A
Bài 1. Bài toán và thuật toán (xác định bài toán, viết thuật toán): Cho dãy gồm N số nguyên a1,...,aN. a) Tính tổng các số hạng có giá trị chẵn/lẻ có trong dãy. b) Tính tổng các số hạng có vị trí chẵn/lẻ có trong dãy. c) Đếm các số hạng có giá trị chẵn/lẻ/bằng K có trong dãy.
cho n nguyên dương và dãy A gồm N số nguyên a1,a2...an. a, đếm số lượng số lẽ trong dãy .b tính tổng các số chia hết cho 3 và 4. c đưa ra vị trí của các số chẵn hỏi out là gì?
a: #include <bits/stdc++.h>
using namespace std;
long long n,i,x,dem;
int main()
{
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2!=0) dem++;
}
cout<<dem;
return 0;
}
Viết chương trình nhập từ bàn phím dãy số nguyên A gồm N phần tử a1, a2, …, aN (1 £ N £ 100) 1- Tính tổng các số lẻ chia hết cho 3 2- Đếm các số chẵn ở vị trí lẻ 3- Đưa ra mà hình danh sách các số chẵn chia hết cho 5 Giúp tui zoiiii
program BaiToanMang;
var
A: array[1..100] of integer;
N, i, demChan, tongLeChia3: integer;
begin
write('Nhap so phan tu cua mang: ');
readln(N);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to N do
begin
write('a[', i, ']= ');
readln(A[i]);
end;
tongLeChia3 := 0;
for i := 1 to N do
begin
if (A[i] mod 2 = 1) and (A[i] mod 3 = 0) then
begin
tongLeChia3 := tongLeChia3 + A[i];
end;
end;
writeln('Tong cac so le chia het cho 3: ', tongLeChia3);
demChan := 0;
for i := 2 to N do
begin
if (A[i] mod 2 = 0) and (i mod 2 = 1) then
begin
demChan := demChan + 1;
end;
end;
writeln('So phan tu chan o vi tri le: ', demChan);
writeln('Cac so chan chia het cho 5: ');
for i := 1 to N do
begin
if (A[i] mod 2 = 0) and (A[i] mod 5 = 0) then
begin
write(A[i], ' ');
end;
end;
end.
ko bt đúng ko ko dùng pascal nhiều
Cho thuật toán, giải bằng 2 cách liệt kê và vẽ sơ đồ khối
Bài 1: Cho dãy A gồm N số nguyên A1…AN. Hãy tính tổng các số các số chẵn và tổng các số lẻ có trong dãy.
Bài 2: Cho dãy A gồm N số nguyên A1…AN. Hãy đếm tất cả các số chẵn trong dãy.
Bài 3: Cho dãy A gồm N số nguyên A1…AN. Hãy cho biết có bao nhiêu số trong dãy có giá trị bằng 0.
Bài 4: Cho dãy A gồm N số nguyên A1…AN. Hãy đếm tất cả các số chẵn không âm trong dãy.
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long n,x,i,t1,t2;
int main()
{
cin>>n;
t1=0; t2=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0) t1=t1+x;
else t2=t2+x;
}
cout<<t1<<" "<<t2;
return 0;
}
Cho số nguyên dương N ( N ≤ 250 ) và dãy n số nguyên dương A1 A2,..., An mỗi số đều không vượt quá 500. Yêu cầu:
1) Đếm số lượng các phần tử có giá trị lẻ trong dãy số A.
2) Tính tổng giá trị các phần tử đứng vị trí chẵn trong dãy số A
3) Tính tổng giá trị các phần tử đứng vị trí lẻ trong dãy số A.
4) Tính tổng giá trị các phần tử là số chẵn đứng ở vị trí chẵn trong dãy A.
5) Tính tổng giá trị các phần tử là số lẻ đứng ở vị trí lẻ trong dãy A.
6) Tính trung bình cộng các phần tử trong dãy.
uses crt;
var a:array[1..250]of integer;
i,n,dem,t,t1,t2,t3,t4:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=250);
for i:=1 to n do
begin
repeat
write('A[',i,']='); readln(a[i]);
until (0<a[i]) and (a[i]<=500);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2=1 then inc(dem);
writeln('So phan tu co gia tri le la: ',dem);
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+a[i];
writeln('Tong cac phan tu co chi so chan la: ',t);
t1:=0;
for i:=1 to n do
if i mod 2=1 then t1:=t1+a[i];
writeln('Tong cac phan tu co chi so le la: ',t1);
t2:=0;
for i:=1 to n do
if (i mod 2=0) and (a[i] mod 2=0) then t2:=t2+a[i];
writeln('Tong cac phan tu chan co chi so chan la: ',t2);
t3:=0;
for i:=1 to n do
if (i mod 2=1) and (a[i] mod 2=1) then t3:=t3+a[i];
writeln('Tong cac phan tu co chi so le la: ',t3);
t4:=0;
for i:=1 to n do
t4:=t4+a[i];
writeln('Trung binh cong cac so trong day la: ',t4/n:4:2);
readln;
end.
: Viết chương trình nhập vào một dãy số A gồm N số nguyên a1, a2,…,an (n<=300, |ai| <= 40000).
a. Tính tổng dãy số A.
b. Tính tổng các số chia hết cho 3 có trong dãy số trên.
c. Đếm số lượng số chẵn, lẻ có trong dãy số trên.
f. tìm phần tử lớn nhất, nhỏ nhất của dãy số.
g. Tính tổng bình phương các số âm có trong dãy số trên.
cho dãy A gồm N số nguyên A1,A2,...,An. hãy viết thuật toán theo phương pháp liệt kê cho các câu hỏi saua, tính tổng các số dương trong dãy Ab,tính tổng bình phương các số chia hết cho 2 trong dãy Ac,đếm số lượng các số là ước của 3d,tính tích các số là số lẻ, số chẵn d, đếm số lượng các số chia hết cho 2 và 5mọi người mỗi người giúp em 1 phần được không ạ:(( em cảm ơn
Lập trình giải quyết bài toán sau cho số nguyên dương N (N<-500) và dãy số nguyên a1,a2,...aN. Tính và đưa ra màn hình tổng các số chẵn ở vị trí lẻ trong dãy.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,t;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
for (i=1; i<=n; i++)
if (a[i]%2==0 && i%2==1) t+=a[i];
cout<<t;
return 0;
}
Viết chương trình nhập từ bàn phím số nguyên dương N (N<=100) và dãy A gồm N số nguyên , A1, A2,...,An
a) Đếm số hợp số chẵn và số lẻ
b) Tính tổng các số chẵn
c) đếm số lượng nguyên tố trong dãy
uses crt;
var a:array[1..100]of integer;
i,n,tc,tl,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tc:=0;
tl:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then tc:=tc+a[i]
else tl:=tl+a[i];
end;
writeln('Tong cac so chan la: ',tc);
writeln('Tong cac so le la: ',tl);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day so la: ',t);
readln;
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem1,dem2,t1,dem3,j,kt:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
readln(a[i]);
dem1:=0;
dem2:=0;
t1:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
dem1:=dem1+1;
t1:=t1+a[i];
end;
else dem2:=dem2+1;
end;
dem3:=0;
for i:=1 to n do
if (a[i]>1) then
begin
kt:=0;
for j:=2 to trunc(sqrt(a[i])) do
if a[i] mod j=0 then kt:=1;
if kt=0 then dem3:=dem3+1;
end;
writeln(dem1, ' ',dem2);
writeln(t1);
writeln(dem3);
readln;
end.