Cho một dãy số gồm n số thực và số thực x. Viết chương trình nhập n số thực đó và đếm xem có bao nhiêu số trong dãy không lớn hơn x ( Sử dụng dãy số)
Cho một dãy số gồm n số thực và một số thực x viết chương trình nhập n số thực đó và đếm xem có bao nhiêu số trong dãy bằng số thực x
#include <bits/stdc++.h>
using namespace std;
long long a[100],i,n,x,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
cin>>x;
dem=0;
for (i=1; i<=n; i++)
if (x==a[i]) dem++;
cout<<dem;
return 0;
}
Câu 4. Viết chương trình nhập một dãy gồm n số từ bàn phím, đếm xem có trong đó có bao nhiêu số lớn hơn 10 và nhỏ hơn 20. Tính tổng các số lớn hơn 10 và nhỏ hơn 20 đó. In kết quả tính được ra màn hình.
Câu 5. Viết chương trình nhập một dãy gồm n số nguyên từ bàn phím, đếm xem có trong đó có bao nhiêu số là số chẵn. Tính tổng các số chẵn đó. In kết quả tính được ra màn hình.
Mọi người giúp em với ạ! Em cảm ơn nhiều!
Câu 4:
uses crt;
var a:array[1..100]of integer;
i,n,dem,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to n do
if (10<a[i]) and (a[i]<20) then
begin
inc(dem);
t:=t+a[i];
end;
writeln('So phan tu lon hon 10 va nho hon 20 la: ',dem);
writeln('Tong cac phan tu lon hon 10 va nho hon 20 la: ',t);
readln;
end.
Câu 5:
uses crt;
var a:array[1..100]of integer;
i,n,dem,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
inc(dem);
t:=t+a[i];
end;
writeln('So so chan la: ',dem);
writeln('Tong cac so chan la: ',t);
readln;
end.
viết chương trình sử dụng biến mảng để nhập một dãy số gồm N số nguyên từ bàn phím và thực hiện: +tính tổng các số trong dãy đó. +in ra màn hình các số lớn hơn 50 trong dãy số đó. +tìm số nhỏ nhất trong dãy đó Cần gấp ạ
var a:array[1..1000] of integer;
i,n,min:integer;
s:longint;
begin
write('n = ');readln(n);
for i:=1 to n do
begin
write('Nhap so thu ',i,' = ');readln(a[i]);
s:=s+a[i];
end;
writeln('Tong la ',s);
min:=a[1];
for i:=2 to n do
if a[i] < min then min:=a[i];
write('Cac so chan la ');
for i:=1 to n do
if a[i] mod 2 = 0 then write(a[i]:8);
writeln;
write('so nho nhat la ',min);
readln
end.
Viết chương trình nhập số n nguyên dương và dãy số thực B1, B2,... Bn. Và số thực x ( theo C++)
- Xuất dãy vừa nhập;
- Tìm giá trị lớn nhất trong dãy;
- Tính trung bình cộng các phần tử lớn hơn số thực x
#include <bits/stdc++.h>
using namespace std;
double b[100],x,ln,t;
int i,n,dem;
int main()
{
cin>>n;
ln=-1e10;
for (i=1; i<=n; i++)
{
cin>>b[i];
ln=max(ln,b[i]);
}
for (i=1; i<=n; i++)
cout<<b[i]<<" ";
cout<<endl;
cout<<ln<<endl;
t=0;
dem=0;
for (i=1; i<=n; i++)
if (a[i]>x)
{
t=t+a[i];
dem++;
}
cout<<fixed<<setprecision(2)<<t/(dem*1.0);
return 0;
}
Giúp em với:(( Cho một dãy gồm m số nguyên Viết chương trình nhập m số nguyên đó và đếm xem có bao nhiêu số chẵn trong dãy m số vừa nhập
Viết chương trình nhập một dãy số nguyên gồm N phần tử (N<=1000). Đếm xem dãy có bao nhiêu phần tử là số nguyên tố và tính tổng các số nguyên tố trong dãy.
Program HOC24;
var d,i,n: integer;
a: array[1..1000] of integer;
t: longint;
function nt(x: longint): boolean;
var j: longint;
begin
nt:=true;
if (x=2) or (x=3) then exit;
nt:=false;
if (x=1) or (x mod 2=0) or (x mod 3=0) then exit;
j:=5;
while j<=trunc(sqrt(x)) do
begin
if (x mod j=0) or (x mod (j+2)=0) then exit;
j:=j+6;
end;
nt:=true;
end;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
d:=0; t:=0;
for i:=1 to n do
if nt(a[i]) then
begin
d:=d+1;
t:=t+a[i];
end;
writeln('Co ',d,' so nguyen to trong day');
write('Tong cac so nguyen to trong day la: ',t);
readln
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem,t,j,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then
begin
inc(dem);
t:=t+a[i];
end;
end;
writeln('So luong so nguyen to la: ',dem);
writeln('Tong cac so nguyen to la: ',t);
readln;
end.
Cho 1 số nguyên n được nhập từ bàn phím và dãy số nguyên a1,a2,...,ăn. Hãy viết chương trình đếm xem trong dãy đó có bao nhiêu số chẵn
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,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 vào 1 dãy số nguyên gồm N phần tử(N<=100) và thực hiện: _Tính tổng các số âm trong dãy vừa nhập _Đếm số lượng các số chia hết cho 3 nhưng không phải là số chẵn trong dãy đó
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.