Giúp mình với ạ
Nhập vào dãy số nguyên gồm n số.In ra màn hình các số nguyên tố và số lượng số nguyên tố có trong dãy đó.Tính tổng các số nguyên tố trên.
giúp mình với ạ :<
Viết chương trình nhập từ bàn phím một dãy số nguyên dương gồm N (N <= 100) phần tử mỗi phần tử có giá trịnh không quá 500. Hãy in ra màn hình số lượng các phần tử trong dãy là số nguyên tố và tổng các số nguyên tố đó .
viết chương trình nhập vào một dãy số nguyên n phần tử, n nhập từ bàn phím.
a) In ra màn hình dãy số vừa nhập xếp theo thứ tự tăng dần.
b) In ra màn hình các số nguyên tố trong dãy số vừa nhập và đếm xem đã nhập vào bao nhiêu số nguyên tố.
Viết chương trình nhập vào dãy gồm n phần tử (n<15). Sau đó in ra màn hình giá trị các phần tử đó và cho biết có bao nhiêu phần tử có giá trị là số nguyên tố , in ra màn hình các số nguyên tố đó.
1. Cho một dãy số gồm N phân tử, in ra màn hình các số nguyên tố có trong dãy
uses crt;
var a:array[1..100]of integer;
i,n,j,kt: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]>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 write(a[i]:4);
end;
readln;
end.
Hãy viết chương trình pascal nhập tên và lớp của học sinh, nhập từ bàn phím dãy số nguyên gồm n phần tử(n nhập từ bàn phím) n<12, tính trung bình cộng của dãy số trên và in ra màn hình, in ra màn hình các số nguyên tố của dãy số trên.
program TinhTBCTimSoNT;
var
ten, lop: string;
n, i, tong, dem: integer;
A: array [1..11] of integer;
trung_binh: real;
function LaSoNguyenTo(x: integer): boolean;
var
i: integer;
begin
if x < 2 then
LaSoNguyenTo := false
else if x = 2 then
LaSoNguyenTo := true
else if x mod 2 = 0 then
LaSoNguyenTo := false
else
begin
i := 3;
while (i <= trunc(sqrt(x))) and (x mod i <> 0) do
i := i + 2;
LaSoNguyenTo := x mod i <> 0;
end;
end;
begin
// Nhập tên và lớp của học sinh
write('Nhập tên của học sinh: ');
readln(ten);
write('Nhập lớp: ');
readln(lop);
// Nhập dãy số nguyên và tính trung bình cộng
repeat
write('Nhập số phần tử của dãy số (n<12): ');
readln(n);
until n < 12;
tong := 0;
for i := 1 to n do
begin
write('Nhập phần tử thứ ', i, ': ');
readln(A[i]);
tong := tong + A[i];
end;
trung_binh := tong / n;
// In tên, lớp, dãy số và trung bình cộng ra màn hình
writeln('Học sinh: ', ten);
writeln('Lớp: ', lop);
write('Dãy số: ');
for i := 1 to n do
write(A[i], ' ');
writeln;
// In các số nguyên tố của dãy số ra màn hình
writeln('Các số nguyên tố của dãy số:');
for i := 1 to n do
if LaSoNguyenTo(A[i]) then
writeln(A[i]);
end.
Viết chương trình nhập vào bàn phím một dãy số nguyên gồm n phần tử a.Tính tổng các phương trình có giá trị lẻ b.In ra các số chính phương trong dãy c.In ra các số nguyên tố trong dãy d.Sắp xếp dãy theo thứ tự tăng dần e.Kiểm tra dãy số trên có lập trình cấp số cộng hay không?
uses crt;
var a:array[1..100]of integer;
i,n,t,kt,j:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
t:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t+a[i];
writeln(t);
for i:=1 to n do
if trunc(sqrt(a[i]))=sqrt(a[i]) then write(a[i]:4);
writeln;
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 write(a[i]:4);
end;
readln;
end.
a.Viết chương trình nhập vào 1 số nguyên n in ra màn hình các số chẵn in ra từ 1 đến n b.Viết chương trình nhập 1 dãy số nguyên n phần tử kiểm tra xem n có phải số nguyên tố hay không
c.Viết chương trình nhập vào 1 dãy số nguyên gồm n phần tử in ra màn hình các số chia hết cho 2
d. Viết chương trình 1 dãy số nguyên gồm n phần tử in ra màn hình số nhỏ nhất có trong dãy.
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;
}
BT1: Cho số nguyên n, dãy số a1, a2, …, an. Dùng vector a/ Tính số lượng các chẵn trong dãy. b/ tính tổng các số nguyên tố trong dãy. (ghi code c++ giúp mình với ạ)
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.