viết chương trình pascal nhập các mảng số nguyên và xuất ra các phần tử chẵn nhỏ hơn 20
ai giúp với ạ !!!
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.
Câu 1:
program mangsonguyen;
var
a: array[1..100] of integer;
i, n: integer;
begin
writeln('Nhap so phan tu trong mang: ');
readln(n);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
writeln('Mang vua nhap la:');
for i := 1 to n do
write(a[i], ' ');
end.
Câu 2:
program trungbinhcong;
var
a: array[1..100] of integer;
i, n, k, sum: integer;
avg: real;
begin
writeln('Nhap so phan tu trong mang: ');
readln(n);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
writeln('Nhap so k: ');
readln(k);
sum := 0;
for i := 1 to n do
begin
if a[i] <= k then
sum := sum + a[i];
end;
if sum > 0 then
begin
avg := sum / n;
writeln('Trung binh cong cac phan tu co gia tri <= ', k, ' la: ', avg:0:2);
end
else
begin
writeln('Khong co phan tu nao co gia tri <= ', k);
end;
end.
Câu 3:
program DemSoNguyenTo;
var
a: array [1..100] of integer;
i, j, n, count: integer;
laSoNguyenTo: boolean;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
write('Nhap cac phan tu cua mang: ');
for i := 1 to n do
readln(a[i]);
count := 0;
writeln('Cac so nguyen to trong mang la: ');
for i := 1 to n do
begin
laSoNguyenTo := true;
for j := 2 to (a[i] div 2) do
begin
if (a[i] mod j = 0) then
begin
laSoNguyenTo := false;
break;
end;
end;
if laSoNguyenTo and (a[i] > 1) then
begin
writeln(a[i]);
count := count + 1;
end;
end;
writeln('Tong so cac so nguyen to la: ', count);
readln;
end.
program XuatSoChan;
uses crt;
const
Max_N = 20;
type
MangSoNguyen = array [1..Max_N] of integer;
var
A: MangSoNguyen;
i, n: integer;
begin
clrscr;
write('Nhap so luong phan tu cua mang: ');
readln(n);
writeln('Nhap cac phan tu vao mang:');
for i := 1 to n do
begin
write('A[', i, ']: ');
readln(A[i]);
end;
writeln('Cac so chan trong mang la:');
for i := 1 to n do
begin
if A[i] mod 2 = 0 then
writeln(A[i]);
end;
readln;
end.
6:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,A[100],i,dem=0;
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
for (int i=1;i<=n; i++)
if (A[i]%2!=0) dem++;
cout<<dem;
return 0;
}
5:
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,nn=1e6,A[1000];
cin>>n;
for (int i=1; i<=n; i++) cin>>A[i];
for (int i=1; i<=n; i++)
nn=min(nn,A[i]);
for (int i=1; i<=n; i++)
if (nn==A[i]) cout<<i<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t,dem;
int main()
{
cin>>n;
dem=0;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0 && x>10) t+=x;
if (x%2!=0 || x<100) dem++;
}
cout<<t<<" "<<dem;
return 0;
}
Bài 1:
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t;
int main()
{
cin>>n;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if ((x<0) and (x%2!=0)) t=t+x;
}
cout<<t;
return 0;
}
uses crt;
var a:array[1..100]of integer;
i,n,dem,max,t,min,dem1:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
max:=-32000;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
dem:=dem+1;
if max<a[i] then max:=a[i];
end;
if dem=0 then writeln('Trong day khong co so chan')
else begin
writeln('So so chan la: ',dem);
writeln('So chan lon nhat la: ',max);
end;
t:=0;
for i:=1 to n do
if i mod 2=1 then t:=t+a[i];
writeln('Tong cac so o vi tri le la: ',t);
min:=maxint;
dem1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then
begin
inc(dem1);
if min>a[i] then min:=a[i];
end;
if dem1=0 then writeln('Trong day khong co so le')
else writeln('So le nho nhat la: ',min);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t1,t2,t3;
int main()
{
cin>>n;
t1=0; t2=0; t3=0;
for (i=1; i<=n; i++)
{
cin>>x;
t1+=x;
if (x%2==0) t2+=x;
else t3+=x;
}
cout<<t1<<" "<<t2<<" "<<t3;
return 0;
}
Câu 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 2=0 then t:=t+a[i];
writeln(t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n: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
if (a[i] mod 2=0) and (a[i]<20) then write(a[i]:4);
readln;
end.