viết chương trình nhập vào số nguyên dương n và dãy a có n số nguyên a1,a2,a3,...,an. tính giá trị trung bình của các số có giá trị dương ở vị trí lẻ ra màn hình
Viết chương trình nhập vào dãy số gồm có N phần tử a1, a2, a3,…,an (N<=100). Các phần tử của dãy số là các số nguyên (với n là số nguyên dương được nhập vào từ bàn phím). Thực hiện các yêu cầu sau:.
a. In ra màn hình giá trị của các phần tử vừa nhập
Tính tổng các số vừa nhập và in kết quả ra màn hình
Var a:array[1..100] of integer;
i,n:integer;
s:longint;
Begin
Write('n = ');readln(n);
For i:=1 to n do
Begin
Write('Nhap phan tu thu ',i,' = ');readln(a[i]);
s:=s+a[i];
End;
Write('Cac phan tu vua nhap la ');
For i:=1 to n do
Write(a[i]:8);
Writeln;
Write('Tong cua chung la ',s);
Readln
End.
viết chương trình nhập từ bàn phím số nguyên dương N( N<=100) và dãy số nguyên A1,A2,...An có trị tuyệt đối nhỏ hơn 1000. Đưa ra màn hình các thông tin sau :
a. Tổng số nguyên chẵn , tổng số nguyên lẻ của dãy số.
b.Tổng giá trị của dãy số .
ai giúp em với ạ, em xin cám ơn
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.
Viết thuật toán và chương trình nhập từ bàn phím dãy A gồm n phần tử a1, a2, a3,..an có kiểu số nguyên. Tìm và in ra màn hình các phần tử có giá trị lẻ, các phần tử có giá trị chẵn trong dãy A
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 một chương trình nhập n nguyên dương và n số nguyên a1, a2,…,an. a/ Tính tổng các số chẵn của dãy (In kết quả trên một dòng) b/ In các số của dãy nằm ở vị trí chẵn (2,4, 6…) ra màn hình (trên 1 dòng ),
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.
Viết chương trình nhập một dãy gồm N số nguyên A1, A2, ...,AN. Tinh và đưa ra màn hình số lượng các phần tử ở vị trí lẻ chia hết cho 9 có trong dãy
Câu 2: (2.0 điểm) Viết chương trình nhập một số nguyên N từ bàn phím. Tinh và đưa ra màn hình tổng các số chẵn trong đoạn từ 1 đến N.
Câu 3: (1.0 điểm) Viết chương trình nhập một dãy gồm N số nguyên dương B1, B2, ..., BN. Nhập số nguyên X. Đưa ra màn hình vị trí các phần tử chia hết cho X và lớn hơn phần tử nhỏ nhất có trong dãy.
giúp em với ạ
Cho số N nguyên dương và dãy số nguyên A gồm a1, a2,.....,an.
Hãy viết thuật toán
a) đưa ra màn hình tổng số các giá trị trong dãy
(Ví dụ: nhập n=4
Dãy A: 3 6 2 1 đưa ra màn hình tổng số bằng 12 <dạng> )
b) Đưa ra màn hình vị trí chứa giá trị lớn nhất. Nếu có 2 GTLN thì dưa ra vị trí nhỏ nhất chứa GTLN.
a:
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n;i++)
{
cin>>x;
t=t+x;
}
cout<<t;
return 0;
}
Viết chương trình nhập vào số nguyên dương N và dãy gồm N số nguyên A1,A2,...,AN và số nguyên k.Đếm xem trong dãy có bao nhiêu phần tử có giá trị bằng k
uses crt;
var a:array[1..100]of integer;
i,n,dem,k: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);
dem:=0;
for i:=1 to n do
if a[i]=k then inc(dem);
writeln('Trong day co ',dem,' phan tu co gia tri bang ',k);
readln;
end.