1. Nhập vào dẫy số A gồm có n phần tử, in ra những phần tử là số nguyên tố (pascal)
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.
Bài 1
Var a:array:[1..99] of integer;
i,n:integer;
s:longint;
Begin
Repeat
Write('n = ');readln(n);
Until (n > 0) and (n < 100);
For i:=1 to n do
Begin
Write('Nhap diem thu ',i,' = ');readln(a[i]);
if a[i] mod 2 = 0 then s:=s+a[i];
End;
Write('Cac so vua nhap la: ');
For i:=1 to n do
Write(a[i]:8);
writeln;
write('Tong cac so chan la ',s);
Readln
End.
Bài 2
Var a:array:[1..99] of integer;
i,n:integer;
s:longint;
Begin
Repeat
Write('n = ');readln(n);
Until (n > 0) and (n < 100);
For i:=1 to n do
Begin
Write('Nhap diem thu ',i,' = ');readln(a[i]);
if a[i] mod 2 <> 0 then s:=s+a[i];
End;
Write('Cac so vua nhap la: ');
For i:=1 to n do
Write(a[i]:8);
writeln;
write('Tong cac so le la ',s);
Readln
End.
Program HOC24;
var a: array[1..1000] of integer;
i,n,d: integer;
tbc: real;
t: longint;
begin
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 t:=t+a[i];
writeln('Tong cac phan tu cua mang la: ',t);
d:=0;
for i:=1 to n do if a[i]=5 then d:=d+1;
writeln('Co ',d,' phan tu co gia tri bang 5');
tbc:=0;
for i:=1 to n do if a[i] mod 2=1 then tbc:=tbc+a[i];
tbc:=tbc/n;
writeln('Trung binh cong cac phan tu le la: ',tbc:6:2);
write('Mang sau khi thay la: ');
for i:=1 to n do if a[i]=0 then a[i]:=10;
for i:=1 to n do write(a[i],' ');
readln
end.
Bài 1:
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 then write(a[i]:4);
readln;
end.
Bài 2:
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 then write(a[i]:4);
readln;
end.
c:
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]%2==0) cout<<a[i]<<" ";
return 0;
}
d:
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,nn;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
nn=a[1];
for (i=1; i<=n; i++) nn=min(nn,a[i]);
cout<<nn;
return 0;
}
uses crt;
var a:array[1..1000]of integer;
i,n,t,j:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do
begin
t:=0;
for j:=1 to a[i] div 2 do
if a[i] mod j=0 then t:=t+j;
if t=a[i] then write(a[i]:4);
end;
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,a[1000],t;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
cin>>x;
t=0;
for (i=1; i<=n; i++)
if (a[i]!=x)
{
cout<<a[i]<<" ";
t+=a[i];
}
cout<<endl;
cout<<t;
return 0;
}
uses crt;
var b:array[1..5]of integer;
i,n,dem,k,tam,j:integer;
kt:boolean;
begin
clrscr;
n:=5;
for i:=1 to n do readln(b[i]);
for i:=1 to n do write(b[i]:4);
writeln;
dem:=0;
for i:=1 to n do if b[i] mod 2=0 then dem:=dem+1;
writeln('So luong so chan la: ',dem);
readln(k);
kt:=false;
for i:=1 to n do
if b[i]=k then
begin
write(i:4);
kt:=true;
end;
if (kt==false) then writeln('Khong co k trong day')
else writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if b[i]>b[j] then
begin
tam:=b[i];
b[i]:=b[j];
b[j]:=tam;
end;
for i:=1 to n do write(b[i]:4);
readln;
end.
program SoNguyenTo;
var
A: array[1..100] of integer;
n, i, j: integer;
snt: boolean;
begin
write('Nhap so phan tu: ');
readln(n);
for i := 1 to n do
begin
write('Nhap phan tu A[', i, ']: ');
readln(A[i]);
end;
writeln('Cac so nguyen to trong day:');
for i := 1 to n do
begin
snt := true;
if A[i] < 2 then
snt := false
else
for j := 2 to round(sqrt(A[i])) do
if A[i] mod j = 0 then
begin
snt := false;
break;
end;
if snt = true then
writeln(A[i]);
end;
end.
program SoNguyenTo;
var
A: array[1..100] of Integer;
i, n: Integer;
isPrime: Boolean;
function IsNumberPrime(num: Integer): Boolean;
var
j: Integer;
begin
IsNumberPrime := True;
if num <= 1 then IsNumberPrime := False
else
for j := 2 to Round(Sqrt(num)) do
if num mod j = 0 then
IsNumberPrime := False;
end;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
for i := 1 to n do
begin
write('Nhap phan tu thu ', i, ': ');
readln(A[i]);
end;
writeln('Cac so nguyen to trong mang la: ');
for i := 1 to n do
begin
isPrime := IsNumberPrime(A[i]);
if isPrime then
write(A[i], ' ');
end;
end.